The EKF uses a simpler magnetic heading calculation when on the ground and before climbing above 5m due to the possibility of ground based magnetic interference. When it climbs above 5m, it switches to a more accurate 3D method of using magnetometer data and also resets the yaw angle (usually by less than 5deg). This reset event is communicated to the yaw controller which adjusts the demanded yaw to prevent any change in yaw angle that could confuse the pilot.
A yaw reset can also occur earlier if the copter detects the magnetic field changing significantly as it climbs away from the ground. This is done to prevent a large ground based magnetic anomaly (eg taking off from a car roof) from causing toilet bowling after takeoff.
The problem for the pilot arises if the EKF using IMU1 runs into a significant sensor error and there is switch-over to the EKF using IMU2. This can cause significant yaw step events that are not communicated to the control loops. There is a PR that fixes this vulnerability which is being reviewed.