Is it harmful to motors that manipulating the motor in this way?

You can arrange that the power supply is weak enough not to damage the mechanics - basically the current
limits the torque, and its the torque that will overload the mechanical side of things.

Where you need to worry about this possibility the simplest solution is to limit the acceleration in your motor
driver code (or rate of change of PWM, which is what controls the speed).

Most motors are mechanically OK to take full stall braking, its usually the gears and the load that aren't
robust enough. However the larger the motor the more important the issue is as the forces are higher
and the design margins less.

Shorting the terminals of a DC motor at full speed is not recommended as this is the worst
possible overload - never underestimate the power of electromagnetic braking.