It doesn't really fit your symptoms, but:
My tankless has a little plastic flywheel which spins as the water flows through it. If the flywheel stops spinning, the tankless heater assumes that the water has stopped flowing and turns off the heating element. This is a safety feature; if there isn't water flowing to absorb the heat then the tankless can overheat.
The flywheel also stops spinning if it gets encrusted with mineral deposits.
The solution is to disassemble that part of my tankless, take out the plastic parts, soak them in vinegar, brush the deposits off with a toothbrush, then reassemble. It is a bit fiddly but not really that hard to do.
This happens to me every five to eight years or so.