What causes sparking at the brushes?

It is due to the self-induction of the coil undergoing commutation.