A DC motor contains a big coil of wire around an iron core (the armature). This generates the magnetic field necessary to make the motor turn. But, it also acts as an inductor. Inductors resist a change in current - when you turn the power on to the coil, the rise in the current is slowed down. But, when you disconnect the power, the current wants to keep flowing - as the magnetic field collapses it induces a current in the inductor.
Now, where does that current go?
What is the voltage?
Remember Ohm's law?
I = V/R let's re-arrange that to be V = I * R. If we have an open circuit, what is R? Infinite, correct? So any current at all times an infinite resistance results in how much voltage?
OK, it's not that bad in real life, but you can get large voltage spikes. The diodes allow the current to flow so you don't see the very large resistance and build up the very large voltages.
Also, in a brushed motor, you have the mechanical connection between the brushes and the commutator (which carries the current to the armature). As the brushes bounce, and cross boundaries between sectors on the commutator, you generate a lot of higher frequency electrical noise (pulses). Capacitors provide a place for the higher frequency electrical noise to go instead of having it go back into the rest of the circuitry.