The relay coil has significant inductance. When the relay is energized, typically by switching one side of the coil to ground, a magnetic field is created in the coil. When that one side of the coil is disconnected from ground, the inductance tries to maintain current flow as the magnetic field collapses. This causes the voltage at the now disconnected side of the coil to swing positive above the voltage that energized the relay. There are many variables but the voltage can easily swing 50 or 100 Volts above ground for a short time. If you were using a 40V transistor to energize the relay, it can be damaged by excessive voltage. The diode across the coil limits the voltage swing to about 0.7V.