Without having actually seen I'd say the
BCM or GEM under the glovebox is where the headlamp current is switched. Not by relays but by solid state device (MOSFET?), not serviceable. The headlight switch module on the dash connects to the GEM via digital (LIN) bus, and is also a potetential failure point.
But I'd also put my money somewhere on the headlamp unit connections. When the fault is on maybe try thumping or wiggling stuff.