I've crashed an RC helicopter because of a similar software issue. Rotorflight is an OSS flight controller, and it has an internal mode for tracking if the vehicle is on the ground or not that isn't always quite accurate at the margins. If you're touching the ground and it's not in ground-handling mode, the I-term in the PID loop winds up really quickly (because the input isn't producing the expected rotation rate) and flips your model on its side.
Betaflight (flight controller for drones, which rotorflight is based on) has a similar function called "air mode" which is common to either disable or set to a switch for aerobatic drones so that they'll still have full rotation rates at zero throttle.