Humor researchers identify several mechanisms:
Punchlines violate expectations — sexual meaning hidden in innocent setup. The brain resolves the conflict → laughter.
Dirty jokes release psychic tension around taboo topics (sex, excretion, aggression). Laughter discharges repressed energy.
Something threatens norms (violation) but is safe (benign) — e.g., a pun on body parts. The "sweet spot" creates humor.
Awkward topics become manageable when framed as jokes. Laughter normalizes discomfort.
Dirty jokes are a cultural universal — found in every recorded society — suggesting deep evolutionary social function.