The first principle of comedy
. Something is funny when it startles. Therefore, it is essential to build up atmosphere and raise anticipation, then run against it.
In this process, timing is crucial.
Timing isn't measured in seconds, but in 'story time', the internal logic of a story.
Comics are a good way to study the buildup/punchline process in detail because everything is right there on the page and you can read back and forth as much as you like. See Asterix for an example.
A good oral storyteller will lengthen a story with all kinds of crazy details and seemingly irrelevant side lines to improve the buildup, but just as often, the story will repeat or drop to nearly total silence, purely for the sake of timing. And this technique is just as essential in newspaper comics. This is why, in many Peanuts gags of just 4 frames, the 2nd and 3rd frame are no more than silent repetitions of the first picture.
Repetition must be the second rule in comedy. It's an effective technique in enforcing elements of the story's internal world, and you need a credible world before you can surprise. It can also be used as an aid in timing.
Another rule is exaggeration, which is a great tool to build anticipation. But exaggeration is only genuinely funny - to my taste - when presented as normal, and this is the final rule, as far as I can see: dead pan delivery. It really helps here to add seemingly irrelevant detail. Monty Python's How not to be seen sketch is impossible to explain because it is built solely on these techniques: exaggeration (the explosions), silly detail ("This is name, address. He can not be seen."), delivery (a perfectly serious, blank voice), repetition, use of silence and patience to set the timing right. It can probably be repeated orally, but there would be no point: the subject is completely irrelevant to the reasons it's funny.
Most of these rules are also important in any other type of story, and in music.
Disclaimer. I'll admit to spending some effort in being funny in daily life, but I would never dare to try and make any money on it. These rules were formulated on the spot. Consult your friendly local professional before use.