KABOOM! when hitting headlights.....

Check your ignition wiring. Both times I had this happen (more than 30 years between incidents) was due to interruption in ignition. The first time was a loose coil wire. The second was a broken distributor lead. Unburned fuel momentarily accumulated in the exhaust. When ignition was restored, it lit off the fuel with a boom.
I have no idea how your headlight switch could be part of the equation.