Here could be a few possible reasons for this issue:
Faulty Wiring: There may be a short circuit or loose connection between the fan switch, the headlight circuit, or the electrical system.
Overloaded Circuit: If the circuit that controls both the fan and headlights is overloaded, turning on the fan might draw too much power and cause the headlights to go out.
Faulty Fan Switch: The fan switch itself could be faulty, causing unintended interruptions in the electrical circuit.
Electrical System Problem: There might be a more significant issue with the electrical system of the car, leading to electrical malfunctions like this one.
It is important to have a qualified mechanic inspect the car's electrical system and identify the root cause of the issue to ensure the proper function of the fan and the headlights.