|Of course Freud wrote a whole book on this stuff, and I think it's one of his more plausible works and very interesting as a read in its own right (although I should point out that many of his more pun-like jokes translate a hundred years and from German to English VERY bad).|
Basically his premise is that some forms of humour allow the expression of difficult or dangerous or violent or aggressive thoughts in ways that allow the release (which results in the pleasure) without engaging many of the mind's defenses. It's more complex than that when you dig right into it, but basically Freud's theories often come down to this idea of a mind that operates bluntly and reactively with a component that conceals, represses or filters. Some forms of humour in Freud's thought operate by allowing you to to express alarming or controversial impulses in sanctionable ways. For example, the funny cartoons with lots of violence in them somehow 'abstracted', and the jokes that set up the expectations of non-socially sanctioned behaviour (homophobia, sexism or whatever) but then provide an unexpected release in a different direction. Or, of course, just having someone say things you're too scared to say in a way that means you're allowed to respond appropriately.
I'm quite interested in this approach, and used it quite extensively in my (never finished) doctoral work. I was tracing 'pleasure' and identification in two works - Natural Born Killers and Euripides' Bacchae. I was arguing that both of this texts were structured around one fundamental precept - the visceral pleasure of having characters perform actions that you might find interesting or entertaining, but would never contemplate doing in everyday life. So the freedom and lack of constraints of the serial killers are interesting as long as you don't have to think too much about the consequences of their actions - ie. as long as the violence happens to bad people, or is concealed with humour and made somehow 'unreal'. In the Bacchae, a sexy rock star god turns up to punish an uptight bastard. He plays funny tricks which make the revenge and punishment cool and entertaining. Then about halfway through each text they both turn on a dime - the humour fails and you suddenly get scared and horrified by what you've so far been enjoying. Natural Born Killers' big twist being that it tries to set the whole thing up again afterwards, encouraging you to identify with people you now view as monsters.