Capacitors pass AC current and block DC current. The fan is an inductive device - it will be causing an AC waveform to be induced over the DC voltage. The capacitor is basically providing a low resistance path (short circuit) for that AC signal so it doesn't interfere with other parts of the circuitry.