I agree this sounds like a defective thermostat/hi limit switch.
You don't mention maker or model of your water heater.
If you have a suburban, there is a rubber cover you can remove
and find your thermostat's and hi limit's look similar to this--
One side controls LP and the other side is the 120v AC electric.
The thermostat and hi limit are built together as one replaceable unit.
They aren't that expensive and are pretty easy to change.
You can get them online or at most any well stocked RV parts counter.
They come in 2 preset temps.
130 deg and 140. Most folks go with the 140 because the heater is
so small you can get a little more time out of a shower if the water is
Cost about $30 for either the LP 12v side or the electric 120v side.