These are the classic words people use to deflect someone away from being mad, usually at some stupid stunt the speaker has just pulled. It’s a power word designed to minimize what has been said and imply that the person who is angry is simply being a poor sport. It is a perfect way to devalue their target and dismiss their being upset.
Used this way it is a perfect “you aren’t supposed to feel that” denial of the other person’s reaction, the other person’s feelings, and the other person’s actual value as a human being. This is particularly nasty when one realizes that “can’t you take a joke” usually comes after a “prank” that is funny to the prank-er but painful/humiliating to the prank-ee. After all, that is the nature of pranks, the quintessential “I get to laugh at you” form of humor.
People also use the phrase to get out of the consequences of saying something nasty. The speaker truly meant it but, realizing that the crowd does not approve, they are trying to get out of the consequences of their words. In this way too, it is a power word, seeking to retain control of the conversation and turn their sincerely meant viciousness into a harmless “oh look, Joe is just being silly” moment.
In both cases, person A does something vicious to person B and then attempts to make Person B feel ashamed for their anger at being physically or verbally attacked. You see, it’s all person B’s fault for being hurt, they just “can’t take a joke” because they’re too humorless and grim to have fun. In truth, A. B, and their audience all know that A really meant it but complaining is now “bad manners” and “rude.”
So yes, let’s add “can’t you take a joke?” to the list of conversational power flags. The words that mean more than what they say and are thus warnings that the speaker is playing crooked pool.