How does a gas water heater thermostat and gas valve work?
There are three things with "thermo" that you need to be aware of. Thermistor, Thermocouple, and Thermopile.

You know what a thermistor is.  A Thermocouple generates voltage when its heated, and the voltage varies with the heat.  A Thermopile is a collection of thermocouples (in a single package) that generates more voltage.

So, the voltage to open the valves comes from thermocouples and the heat comes from a pilot light.

You know how when you light a water heater you have to hold down that button for a long time to get it to stay on?  Well the button manually opens the pilot light valve and you have to hold it on long enough for the thermopile to heat up and take over the job.  Once it's up to heat, it keeps the pilot light valve open and provides voltage for the other controls.  Also, if the pilot light goes out, voltage drops, and all the valves remain safely closed until it is re-lit.