When a motor is decelerating or braking, it generates excess energy that needs to be dissipated to prevent damage to the motor and control system. In dynamic braking, a braking circuit is activated to switch the motor from a power-generating mode to a braking mode, and the kinetic energy of the motor is converted into electrical energy, which is then dissipated through a braking resistor.