You are correct that the motors on one side speed up.
The reason the drone doesn’t lose too much altitude is that the motors speeding up on one side, and the resultant force of gravity on the other side, create a torque about the pitch (or roll, depending on if it’s a flip or roll) axis.
In other words, as one side goes up, the other side goes down.
This can be difficult to visualise, so here is something you can try in real life:
Take a ruler and balance it with a finger at either end. Remove one of the fingers and you will see that by the time the ruler has completed one full roll, it has lost altitude.
However, try it again but this time, as you remove one finger, raise the other one sharply. You’ll see that the ruler barely loses any altitude by the time it has completed a full roll.