Grice. Grice Grice Grice Grice Grice.
Paul Grice did seminal work in the philosophy of language, on how we recover meaning from an interlocutor’s words. It is clear that we routinely understand more—or less—than what our interlocutor says. To make sense of this, Grice developed a notion of conversational implicature. This is what we consider to be implicit in what the other is saying; but unlike logical entailment, it is fallible, and defeasible (more information or clarification can establish that our guess was wrong: it works as a default assumption, rather than a universal truth).
We arrive at conversational implicatures, in turn, through assumptions about how conversation works. Grice’s maxims are the ones that get taught in Undergrad Pragmatics, but the underlying Cooperative Principle is what matters here. It is the assumption that the person you are talking with is not a psycho, and that what they are saying somehow makes sense, is relevant to what we’re talking about, and is situated on the same planet as you are. Or, to put it in his terms,
Make your contribution such as it is required, at the stage at which it occurs, by the accepted purpose or direction of the talk exchange in which you are engaged.
That assumption is what makes irony work, and for that matter what makes humour work. If someone gives you a response that is manifestly untrue and irrelevant, they could be being a psycho. But your assumption under the Cooperative Principle is that they are not being a psycho, that what they have just said is relevant, and that you have to dig a bit deeper to work out what the relevance is. People in fact expect that you will do that digging, which is why a lot of those seemingly psycho irrelevant responses become conventionalised—and the implicature of what they mean becomes a conventional implicature: an implicature that is still not the literal meaning of what is said, but which we by default associate with the expression anyway. (E.g. “sounds legit”.)
What follows from that is that we have strong expectations of what someone should be saying at any point, and of how the world works. And if they say the opposite to what we expect, or of how we know the world works, we assume that they are somehow joking. In fact, humour relies on us assuming that they are somehow joking.