http://www.4qdtec.com/pwm-01.html
We have already seen that the MOSFET is a bi-directional switch which conducts resistively (when it is turned on) for both directions of current. So consider the situation when the current is zero and the controller's output is now reduced. The motor's back e.m.f. is now higher than the controller's output voltage - so the motor will try and feed current back into the controller. If it succeeds in so doing the motor will be braked - we will have regenerative braking.
This type of circuit (where hi-side is turned on when the loside is off) is capable of sourcing current or sinking it. The way this works is that the reversed motor current is now a forward current to the flywheel MOSFET so when this is on it shorts out the motor - whose braking current rises during this period (arrow B, reversed). The Flywheel MOSFET now turns off, but this current must keep flowing - because of the motor's inductance. So it flows as reverse current through the drive MOSFET, recharging the battery as is does so. The extra voltage for this is derived from the energy stored in the motor's inductance.
The process of switching from drive to braking is entirely automatic. Moreover it is done entirely by the motor's speed exceeding the drive voltage and without any change of state or switching within the controller. The regen braking is, if you like, a by-product of the design of the controller and almost a complete accident.