By asking/telling someone to smile, one is basically saying, "You should look more pleasant for my benefit." I can't see asking someone to smile being appropriate in a workplace setting unless the person is in a customer-facing role and it affects job performance. The sexist part is that it seems to happen far more often to women than to men.
That's quite an assumption (that it has anything to do with physical appearance).
It's equally possible that it was intended as a 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.
Sure, I can see contexts where it would be inappropriate to say but that doesn't make it always inappropriate to say.