I'm sure you have more experience with it than me, and I don't mean the following in a bad/negative/rude way, but do you guess this or know this?
I would translate an (elevator) stick input to a "fly in this heading with this velocity" (Earth reference frame), and have the drone calculate the required angles based on compass IMU and GPS.
What you say they do is translate an (elevator) stick input to "put the drone at this (pitch) angle" (drone reference frame), and then apply compass IMU and GPS calculations. This seems like a mucky way to do it because now you have a stick input pitch angle and a different actual pitch angle (because of wind it can even have an actual angle tilting back while the pitch input is forwards). This will also mess with the expo and gain settings which makes the whole setup a recipe for mistakes.
I think in P-GPS mode moving the stick is not a command to the drone reference frame, but to the earth reference frame. Only in ATTI mode is a stick command an input to the drone reference frame (because in ATTI stick pitch == drone pitch). If this is true a drone with the OP's issue, in P-GPS mode would fly backward when giving forward stick input, I think?
I don't have any documentation to support my claim other than this is how I would have designed it.
That's an insightful post, and I understand your argument, but it puts the cart before the horse. You are correct that in P-GPS mode the aircraft will attempt to match track with heading, but it cannot make a course correction until it detects a track. So, even in P-GPS mode, elevator and aileron translate to pitch and roll changes on which the FC will superimpose course corrections to maintain track.
Now if the IMU heading is 180° off then as far as the FC is concerned, initial motion when forward elevator is applied will be in the opposite direction than it expected - it will detect, effectively, that it is moving backwards instead of forwards. Its response will be more forward pitch, not less, to attempt to move in what it wrongly thinks is the forwards direction, which will push it even faster in the direction it is facing. Now we have uncontrolled flight, but forwards, not backwards, probably followed by a high wind warning flag when it is unable to correct for what it detects (incorrectly) as drift that it cannot counter.
On the question of whether I'm guessing - no - it's based on a combination of knowing how sensor fusion works in GPS modes and looking at logs of this actually happening. In this particular example the initial FC response was due to drift rather than stick inputs, but in other cases it has been stick input that triggers the uncontrolled response. The results are both consistent with theory.
So you are entirely correct that the goal of the FC in P-GPS mode is to translate elevator to "fly a track in the direction of the current heading", but your proposed mechanism to do that is not quite correct. It's not going to fly backwards on application of forward elevator because it doesn't know that it is facing the wrong direction, and once it moves in the wrong direction, it assumes that's due to wind and applies even more forward pitch, rather than immediately concluding that its yaw value is out by 180°. Does that make sense?