My toddler nephew likes to play a game where I introduce myself ("Hi, I'm Josh, nice to meet you!") and he replies by introducing himself with a name that isn't his ("Hi, I'm Mario, nice to meet you!" (his name is not Mario)). I react with over-the-top confusion ("Wait, you're not Mario!!"), he laughs uproariously, and then we repeat the game. The joke is, his name ISN'T Mario but he pretends it is!! HAHAHAHA! It's kind of stupid and silly, but it's fun and I love my nephew.
This brand of humor is typical of babies and toddlers. If there's any logic to it, it seems to be reversal of expectations plus a kind of 'inside joke'. He's not Mario. He knows he's not Mario, I know he's not Mario. I know he knows he's not Mario, and he knows I know... etc. It's funny because I play along and he gets to showcase how smart he is by flagrantly saying something wrong; he's not worried that I'll think he's some little baby who doesn't even know his own name. We share a kind of secret together, and that's fun.
It wouldn't be funny if we didn't have the inside joke. If he didn't actually know his name and I acted reacted in this over-the-top way of correcting him, that wouldn't be funny. If I really thought he didn't know his name and I tried to teach him, that also wouldn't be funny. It only works when we hold the second-order knowledge: I know that he knows and so on.
(I get that very small babies don't understand Object Permanence, which is usually used to explain why "Peekaboo" is so fun for them. But kids play Peekaboo way after they learn about OP, because it's a fun game. I didn't disappear. He knows I didn't disappear. I know that he knows...)
I might have guessed we grow out of this kind of "childish humor" by the time we become adults, but I would have guessed wrong. Once I started looking, I started seeing it everywhere!
For example, last week I attended an astrophysics seminar (on Zoom) with some colleagues in Europe. We made chit-chat, and asked about the weather, and one person replied, "Yeah it's always so sunny and beautiful here." We all laughed and played along! You see, this person lives in Hamburg, Germany, a place that is well-known to be dreary and rainy and cold. The joke is, Hamburg ISN'T sunny and beautiful but he pretends it is!! HAHAHAHA!
This is kind of like sarcasm, but also kind of not; he didn't say "sunny and beautiful 🙄" with the modified tone of voice typical of a sarcastic comment. He said it as though he meant it, and that's what made it funny. He knew Hamburg is dreary. We knew Hamburg is dreary. And he knew that we knew that Hamburg is dreary. It wouldn't have been funny if he actually thought it was beautiful there. It wouldn't have been funny if we thought to correct him ("Actually isn't it pretty dreary there?"). It only works when we share the inside joke and play along. He put himself out there, and we all got to be in on it. We share a secret together, and that's fun.
Now that I see this humor pattern all over the place, I see certain present-day issues online in a different light. See, there seems to be a growing industry of digging up 10+ year-old Facebook posts and Tweets making very bad jokes with e.g. racist or sexist themes, and using them to get people fired or cancelled or whatever. However such jokes were interpreted back then, they are, in fact, very not funny now. I can think of two reasons why this is the case.
One reason is that our threshold for offense today has changed; this is the usual excuse people make for those bad jokes. In 70s sitcoms, people thought a good joke was "My daughter's in an interracial relationship, and I'm mad about it!", and of course that would never fly today. In the 90s, people did blackface all the time, and as long as it wasn't an offensive caricature of black people (though blackface historically was), people thought it was funny. Now we look back on that practice nervously and feel pretty bad about it. As a culture, we have changed and I think it's largely for the good. And yet, acknowledgment of our evolution implies that we can't hold people of the past to the same moral standards that we hold ourselves to today. Egregious racism is never ok, but Jimmy Fallon doing an impression of his friend Chris Rock isn't that; in any case, nobody back then thought it was.
A second reason is that we are much more connected than ever before. Making a joke on the internet is like making it at a press conference; you'd better choose your words extremely carefully because lots of people may be listening, not just now but for years to come. People may have different thresholds for moral outrage than you do, but even if not, many will not be on the inside of your inside joke.
Nonetheless, people inexplicably treat Twitter like a group of close friends, sharing ideas and attempted humor that they would never dare say in front of a literal crowd. If your offensive joke could be funny, it would only be so in a context where the audience already knows you and how you feel about the issue in real life; if you have more than a few hundred followers on Twitter, that's likely not the case. Maybe you are, in fact, very not racist, but your race-related joke is especially unfunny in a context where the listeners do not know that.
Comedians are an interesting special case, as they generally get a pass for saying things that people on the street wouldn't be allowed to say. Even so, edgy comics sometimes they feel the need to explain the joke out of a worry that someone will misunderstand.
"If you were offended by that, it was ironic. Isn’t that fun? I meant the whole opposite of it." -Bo Burnham
To conclude, what I'm saying is that: (1) adults engage in the childish, say-a-false-thing-that-you-both-know-is-false joke style quite a lot; and (2) this is a form of inside joke and is funny only (though not always) when the audience already knows where you stand.
I'm a little worried that my argument can be used to justify something I'm very uncomfortable with, namely the proliferation of any number of very offensive jokes behind closed doors. For example, my wife is Jewish and doesn't like Holocaust jokes; is it ok for me to wait until she leaves the room and then tell that kind of joke to my more easy-going friends? That sounds wrong to me (and I wouldn't want to do it anyway). I guess to the extent there are some things you should never joke about, it's not always because people fail to understand that you're saying the opposite of the truth. Either way, know your audience... or perhaps, make sure they know you.
("The joke is, I'm actually NOT racist but I pretend I am!!")