They were introduced in the first Trek film to justify being able to see the ship at all:
“And whoever was designing the process of making the visual effects hadn’t really thought about what I was thinking about, which was how do you see the Enterprise when it’s in deep space, when it’s not near the sun or a star or anything? What’s the source of light? Where’s the key light? Where’s the fill light? How are you going to make this thing beautiful? And my thought about it was how to make it light itself up, kind of like the Titanic at night. And make it light itself up by having lights onboard the nacelles, shining on the fuselage, and from the fuselage shining up on the nacelles, and make it look like it’s self-illuminated. So I didn’t have to justify a key light, because there wouldn’t be one. And no one had ever thought of that."
Not a trekkie…why do spaceships need headlights?
They were introduced in the first Trek film to justify being able to see the ship at all:
https://www.ign.com/articles/2019/12/07/star-trek-the-motion-picture-tmp-enterprise-refit-drydock-douglas-trumbull