It's almost always - perhaps exclusively - directed towards women.
It's brought on by the expectation that females should live their lives in servitude to any and all men.
I guess the whole princess-hero-trope in culture further emboldens men to show - extremely superficial - concern when they encounter a woman who isn't performing a service-minded, bubbly and fascile idea of herself.
If it was ever directed towards a man, it would be treated for the passive-aggressive - if not actually threatening - intrusion that it is.
I'm a gay man, and even if some other gay random dude told me to smile out of the blue, my (inner, emotional) reaction would be deep hostility and contempt for the person who said it.
It's condescending, intrusive and demeaning to tell a stranger to express themselves in a way that you, another stranger, feel might please you, before knowing literaly anything else about the person you're talking to.
It's also about fundamentally not seeing women in any other way than someone who is receptive, attentive, accomodating, and willing to engage with whatever the fuck is currently happening in your loser life, as soon as you lay eyes on them.
If they aren't beaming at you, there must be a problem. Which you can easily address with a friendly reminder to just smile.
The deeper implication is that women don't have interior lives of their own. They don't have a past or future; just a reacting present, easily decoded in an casual fashion by their immediate body language.
It's an infuriating aspect of modern culture, and if it was ever directed towards another man, the result would probably be a bloody bar-fight.