In my experience, when things go on and off on a vehicle it usually points to a bad earth or connection somewhere. Faults like this would require a methodical approach and no assumptions must be made. I’d start with the headlights themselves. If you don’t have the original headlight bulbs, go buy some cheap ones and use them and see if the fault is still there.
Check all your earth connections whilst you are about it too.
Not sure if you have a remote start system (Decosse or other) so there could be something there that could be causing it too.
Also, have you worked on the bike prior to this happening? I should have asked this first..