These types of taxes are common and logic is simple, you have capital gains that accrued during the time you were tax resident in Germany. By rights the taxes on those gains are due to the German state. So you need to do a deemed disposition and pay the relevant taxes.
I had to do the same when moving country and it’s right.