It's difficult and sometimes costly to make assumptions of others' intentions. I usually act upon the words, not what I think is under them. This gives people the respect they are due of not misrepresenting themselves. In other words, unless something is blatantly an awkward attempt at humor, I will take it at face value the first time. The old "say what you mean; mean what you say" stuff.
If their judgement is poor and they are saying things which they don't mean or which don't truly reflect their character, then they are the ones with the problem. If their timing at humor, potentially hurtful though it may be, is off time will tell whether they mean harm or not.
To address Blue, I think people who deliberately mean harm or make a habit to attempt to poke at someone's tender spots, are acting out of unhealed past hurts. And as you intimate, it indirectly has nothing to do with you.
Why does it hurt coming from a stranger? For the same reason they are doing it - something in our past is unhealed and it has just been engaged.
In a sense it is two children acting out something from their pasts. If we keep it in the present it can sometimes be untangled without even addressing the issues.
For instance: "Your sense of humor, or your comment, stings." will let the other person know we've gotten entangled. Keeping the observation in the present, free of judgement and clean of junk helps.
What the person responds will help you to understand whether it was intentional or not.