When you click on links to various merchants on this site and make a purchase, this can result in this site earning a commission. Affiliate programs and affiliations include, but are not limited to, the eBay Partner Network.
Either that or you have a wire shorting out somewhere. I doubt that the headlight switch is the cause based on this...resistance causes heat, heat causes expansion in metal, and if the heat caused by the resistance in the switch was enough to make the metal make contact, it would stay on until it has cooled off. From my experience with the switches, they loose part of their function when they go bad. Not always, but sometimes.
Think about this, did you just go over a bump when it happened? You can check the headlight switch rather easily, and I do recommend doing that, but I think you have a wire with rubbed off insulation that is making contact somewhere else.
Or it could be an intermittant open in the power going to the switch.
If there's a short to ground in the headlight wiring, (or the headlights are drawing too much current), it could open the circuit breaker in the switch. I'm not sure if both the headlights and dash lights would be affected at the same time. I thought the dash lights have their own fuse (and power routing).