The capacitors perform a similar function, but not exactly the same.

The capacitor across a diode acts as a short circuit to any high frequency AC created when the diode turns on and off. The capacitor across a DC motor armature (and often from either end of the armature to ground, as well) helps filter out noise from the brushes, and prevents it from interfering with the control electronics.