I’ve always liked this definition of comedy: “deviance without harm”
Punching down is harmful because the insulting itself it is part of the social marginalization of a group. That said, the way some groups think of each other, punching down is the funniest kind of humor, but that’s another thing.
Punching up is fighting the good fight. It’s deviant to undermine the establishment, and funny because it’s usually goddam true and you still probably won’t end up in legal trouble for saying it.
Dead baby jokes are funny because they are ultimate deviance, but so ridiculous that they can’t be taken seriously, and are thus made harmless (though parents sometimes still don’t like these jokes for some reason).
Self deprecating humor is safe humor because you can attack any personality trait without seemingly attacking a group of people. Humor can always risk offending, but good comedians can turn the punchline on themselves to defuse a joke.