I think there are several things that make things funny, but perhaps the common element is related to what Harp said above: there’s a kind of surprise. I.e., you’re expecting an idea to go one way, and instead it goes in a completely unexpected direction.
There are a number of techniques used to create this surprise. They range from the subtle to the profane. This list is by no means exhaustive: Puns, Potty Humor, Absurdity, Wild exageration, the Unexpected.
Puns create surprise by apparently saying one thing, but then if you take a word differently, it changes the meaning in one or more ways. It is the surprise discovery of the multiple possible meanings that makes us laugh, or in this case, groan.
Potty humor is about the shock not just of the unexpected (flatulence or bad language in inappropriate situations), but in the breaking of taboos. Humor is often allowed to talk about things that are not discussed in polite society. Sex. Menstruation. Defecation. Strombolis. No. Wait. How did that get there? I swear, I didn’t type it! Maybe the flutherbot?
Absurdity works because the surprise comes from things that just can’t happen. They sound plausible on the surface, but gradually they begin to take things out of the world we are used to. The thing is, there’s actually a humor machine. Not the computer program that Harp was talking about, but an honest to god mechanical machine. You feed it grass and paper clips, turn the twisty handle, and out pops the joke. The machine even laughs!
Wild exageration is also known as being over the top. It is perhaps a form of absurdity, but it’s built on an existing situation, and then stretching it one or two or ten steps further, but in this case, it can happen. It’s not absurd like the example above. You know, I tend to go on and on, sometimes, and people get rather tired of me, but do they just stop reading? Oh no. Somehow they seem trapped in my words, reading for hours, until the bitter end, and then, oh yes, then, they take it out on me. You thought my knuckles hurt because of carpal tunnel? Oh no. For some reason, flutherites are partial to thumb screws!
I think a major mechanism in humor is a reliance on the unexpected I’ve shown a few examples of types of unexpectedness above. These things lead to a realization that we’ve been had. But we’ve been had without malice. So our response is delight, and we laugh to show that delight. Or sometimes we groan, because a pun or a joke is so cheesy or awful. Yet, there’s delight in the awfulness, somehow.
The question also asks what funny is. I think this is rather recursive. Or is it discursive? Yeah, yeah, I know. You’re all cursing me now! In any case, as circular as this is, it seems to me that funny is what makes us laugh. The things I described above are ways of achieving funnidom. I’m no expert though. I can’t remember a joke to save my life. I can’t be funny in person, either. The only time I can achieve any semblance of funniness is in the written form, where I have a chance to think.
But a lot of humor is formulaic. Each comedian settles on a format and milks it and milks it. Letterman, Leno, etc etc. They all have a schtick. My schtick is rather unhealthy: self-denigration. (Like saying I can’t be funny). It, I think, appeals to the tenderness people might feel towards someone completely non-threatening. You can feel sorry for him, and laugh at him for the way he fumbles through life. Clueless. But here’s the surprise; the unexpected, I am both utterly clueless on some things and totally clued on other things at the same time. Go figure.