GOOD QUESTION ! It's called a FLYBACK DIODE and it shunts the BACK EMF negative voltage) from the coil when it de-energizes.
Google solenoid back emf