This video shows a gas water heaters magnet assembly. The thermocouple is screwed into the bottom of the magnet assembly. I removed the magnet assembly from the water heater control valve to demonstrate why you must hold the "red button" down while lighting the pilot.
In the video the top of the magnet assembly that I push down with my finger would have a steel rod direcly connecting it to the "red button" you depress to allow gas flow through the control valve to the pilot assembly.
The pilot light heats the thermoscouple to generate millivolts of electricity that charges an electromagnet. Until the thermocouple has been heated enough to charge the magnet you must hold the "red button" down to allow gas flow.
In the video I use a torch to heat the thermocouple and then depress the plunger and the magnet is charged. It holds the spring allowing gas to flow through the valve to the pilot.
When I turn the torch off,that would simulate the pilot being blown out or otherwise not present as to prevent the burner from firing if the thermostat called for flame.
When the electromagnet is no longer being charged the magnet can no longer keep the spring contracted.