I was on the phone with HMRC and my old German tax office, and if I understand correctly, this tax stuff is always codified in a “double-taxation treaty” between two countries. So you need to check with the tax office or an expat tax advisor BEFORE you leave your country to live somewhere else, and the details differ from country to country. I hear e.g. that U.K. expats moving to Thailand may be in for a rude tax awakening for some reason.
In the specific situation of residing in the U.K. and selling shares in Germany, capital gains you make are taxed in Germany (801€ allowance, then 25% and maybe a bit more) and you report the gain to both HMRC and the German tax office. HMRC will then tax you more if selling the shares in the U.K. would have been taxed higher. Otherwise, you get tax credit or something. At least that’s what I think I understood.
I am still biting myself for moving a large pile of GBPs to Germany because at that point I didn’t know about ISAs and T212. Live and learn