The diodes are to prevent high voltage spikes produced when a current flowing thru a coil is interrupted. This can damage the L298.
They also provide a path to dissipate the energy stored in the coil.
Some call them "flyback" diodes.
It is similar to the diode in parallel with the coil of a relay.