It’s been a bug in MSFS since the beginning. I’ve explained this in other threads…
Essentially, there are three barometric pressure registers in FSX. The altimeter uses Baro:1, the AP Baro:2, and the Transponder Baro:3 they are not linked. So if you change the altimeter’s barometric pressure, you are not affecting the barometric pressure basis for the AP. If you hit B, it sets all three registers to the local indicated pressure. And now all three are working from the same altitude pressure basis (the Transponder incorrectly so, as it’s really supposed to ALWAYS display standard pressure altitude). So as @Hyperaspiste said, as you pass the transition altitude and set your Altimeter to standard pressure altitude, the AP Baro stays at local pressure altitude. The Asobo KAP140 has an option to set the barometric pressure in the AP. I don’t believe the Carenado one does (I might be wrong). So it is actually Carenado’s problem technically. They need to add the code to set the barometric pressure for the AP, or link it to the Alitimeter Baro.
For the OP @mobbe123 - What you describe is actually working as designed and as it’s supposed to based on your question. As you fly along and the local barometric pressure changes, often drastically in game. So when you cross that front in game, your autopilot will not remain at the correct altitude because it’s base barometric pressure is incorrect. Hitting the B key corrects it, as designed (but screws you up in the the flight levels).