It's mainly 2 ways for that if the AC don't crash before ... either the flight controller gives up & drop the positional confidence to 0 & go in ATTI mode. The other possibility is that both gyro & compass slowly feed in corrections & over some time corrects the wrongly initialized IMUYaw.... and by the way how come it can fix itself, after like 30 second
The critical moment isn't when you launch ... it's when you power on the AC. It's then the IMUYaw initializes to the compass direction ... so if the compass is deflected there, the IMUYaw will be wrong.by the way almost all my flights are hand launch or launch from concrete surface...
Power on the AC in your out stretched hand (without watches or other magnetic objects) once fully on & the liveview have appeared in the app ... you can safely place it on ground for take off.