Those capacitors are there to absorb transients created by the inductive motor windings. Those transients can cause glitch problems outside of the motor drive system, and give you fits. There is one across the motor, two tied to ground on each motor pin. Since the motor can rotate CCW or CW, the source is floating, so you need those two tied to ground as well as the one bridging the motor input.
Definitely necessary for normal operation.