What does it do?
A thermocouple send a low voltage signal to the gas valve, letting the gas valve know there is a flame and it can stay on.
Why do they go out? Nothing lasts forever. after a while a thermocouple is no longer able to send enough voltage to the gas valve to keep the pilot button set. and it needs to be replaced. Some times you can just relight the pilot and it will hold for a few days then go out again. Most of the time this is a week thermocouple.
How to replace thermocouple scroll down for instructions
The Gas valve is the main control of the gas going to your appliance. There are many different kinds of gas valves. The one in this picture is from a Weil McLain boiler, it is a 24 volt standing pilot gas valve. Not all gas valves are 24 volt standing pilot. and not all Weil McLain boilers have this type of gas valve. Some are mili volt and use a thermopile instead of a thermocouple and are not interchangeable. Others are 120 volts. and are also not interchangeable.