Is this a instant water heater?
Set the temperature lower and knock the flow switch. Most likely is that water flow switch is partially stuck so when it sense that the water is flowing, the heater will cut in, once it sense no water flow it will cut off.
Otherwise check your shower spray, see if the water pressure is good.