One comedy technique, according to former Simpsons and The Office writer Brent Forrester, is the contrast between the sacred and the profane or the high and the low. In Brent’s talks, he gives examples like the farting preacher (farting = profane, religion = sacred) or a TV idea called baby with a machine gun (baby = sacred, guns = profane) or a nun saying penis (you get the gist).
Brent says that you can make a list of things that are sacred and things that are profane. Combine the two lists and voilá you have a comedy technique.
Some of these things might seem a little simplistic, but then he gives the example of the Chuckles the Clown funeral in the Mary Tyler Moore Show (sacred = funeral, profane = laughter).
Note: Brent says that a good punchline often combines more than one comedy technique, so as well as this technique you might have others like irony, wordplay, character, etc.