As said ... your incident was hardware related, if the AC wasn't knocked around & flew normally without any abnormal back & forth drifts when hovering (which usually is signs of a needed IMU calibration) the flight before this happened it's nothing you can/could do to prevent this... a IMU calibration isn't normally needed on a regular basis.... I am not sure I understand if there is anything different that I should do to avoid a repetition of this problem.
Now it's more about finding out if a IMU calibration can fix the odd accelX value that in the end told the IMU that your AC was pitching up by 24 degrees ... if it's possible, try to do a proper IMU calibration on a flat horizontal surface & post the DAT.