Wow, I had no idea people would interpret this as sexual harassment. I say this to both men and women on my teams that look like they are having a rough day. I'll remove that from things I say.
Edit: I don't just say "Smile", usually there is more context to the conversation and usually ends with me trying to see if I can help fix the problem(if it's work related).
You should absolutely try to help cheer people up and fix their problems. Nothing wrong with that. But there's a difference between helping someone feel something and telling them to feel something.
Have you considered that it might not be a command? Human communication is much more nuanced than just the words on their own would indicate.
Where I'm from it's commonly meant as shorthand for "cheer up, it's not that bad" or "try to keep your chin up". Both of which actually indicate that the speaker cares about their colleague.