Hi Iawia,
diodes across an inductive load (relays, solenoids, etc.) prevent damage to the switching transistor.
The collapsing magnetic field around a coil generates a voltage of opposite polarity and a much higher level (called back EMF) than the switching voltage used for the coil, e.g. coil voltage=5V, back EMF might be as high as 30V, destroying the switching transistor.
Observe the direction of the diode. Connection must be with the cathode as shown in the datasheet you provided.
Does that answer your question?
Boncuk