Most modern vehicles have a light sensor that detects when the headlights are turned on or off, and then automatically turns them off or on, respectively. If your vehicle has this function, then it’s likely that it’s functioning fine. You can check this by turning on and off your headlights manually - if it doesn’t turn them off or on, then you need to get your headlight sensor replaced.