Ha, I used to get this a lot. "Smile it might never happen!", "God you look miserable what's happened." (I once responded that my family had just been all killed in an aircrash(they hadn't) and the look was priceless.)
But then even if I'm smiling, which I do a lot, if I happen to be feeling a bit cheerful, which I can quite a lot, then people kind of glare at me as if to say what are you grinning at, so you can't win really!
I used to walk away, but nowadays I kind of see it as a chance to strike up a conversation - although clumsy and a bit annoying, maybe it's a chance to just have a bit of a connection with a random person, who is probably feeling lonely somewhere inside but just doesn't really know how to connect, so they make an inane comment, but maybe there's some attempt to connect there, or that's how i try to see it these days!
I mean imagine that it's a lonely person, who has social anxiety or awkwardness, and they are just trying to break the ice, or talk to a stranger... so they say something a bit daft. It doesn't mean they are criticising you, it might be a big deal for them trying to talk to someone. I tend to find most interactions between strangers tend to be a bit inept or based on a humourous remark, but often comes from a need to connect.