The diode is known as freewheeling/flyback diode.
Imagine that the relay is energised. A current will flow through it and will set up a magnetic field around it.
When the relay is de-energised, this field will collapse as there is no more current to sustain that field. Michael Faraday found out that whenever a magnetic field associated with a coil changes, a voltage will be induced in it.
In our relay, this change in field is rapid and the voltage will be high. This can be damaging to the transistor.
So we put a diode across the coil such that it will short circuit the coil and the voltage across it quickly settles to zero.
I believe this will help.