Headlamp left on

How can I retrofit my Nissan Sentra with an mechanism that will turn off the head lamp when the ignition switch is turned off?

You can’t. No one is going to invent a solution to your imagined or real problem.

The quick and dirty way would be to add a standard automotive relay. Cut the power wire going to the headlamp circuit and connect the two ends to the normally open contacts. Ground one end of the coil, and wire the other end to a circuit that is switched on and off by the key.

A better way would be to buy one of the aftermarket auto headlamps modules. They turn the lights on when it gets dark or if you have the wipers on. The headlamps turn off a minute or two after you turn the car off.

So, I guess that I am imagining the fact that my cars and many others (including the Nissan that I most recently rented) have this feature built in?

The problem is imagined, not the solution.

I’m sorry. Do you know the OP? How do you know that the OP or someone who drive’s the OP’s car doesn’t need this feature?
If you are going to take that attitude, perhaps all of the problems posted on this board are just imagined…

On modern cars with a battery-saver feature all lights will go off after about 30 minutes. I’m not sure if it’s a standalone part that does this or if it’s just something programmed into one of the car’s computers. I know the 2nd gen Altimas and newer Maximas have this feature, I don’t if it can be retrofitted into the Sentra though. Alternatively you could just turn them off with the knob/switch that you use to turn them on in the first place.