Comedy writing is a very particular skill, which like most artistic things, can be learned. Not everyone is going to become P.G.Wodehouse but most people can improve through practice.
There are structures and techniques you can learn, standard formulas and patterns, and so on.
As has been mentioned earlier, it's mostly about seeing another side to something, an unexpected viewpoint. It's about surprise: a bizarre form of word association, thinking around a subject over and over, until you find a satisfying twist, whether that's conceptual, character-based, a play on words or whatever.
I like to do the
New Yorker caption contest with another comedy writer friend of mine, just to get some practice at coming up with ideas. What always amazes me is the range of different joke concepts and punchlines you can come up with for the same picture.
For example, this week's competition is
a two guys and a tree.
We've come up with:
"Am I still in Mexico ?"
"But is it art ?"
and "You're right, it is chewy on the inside."
All jokes based around totally different concepts and implying completely separate scenarios.
I'm sure the winning caption will be much funnier than any of those, and on another topic altogether.
(Go on, see if you guys can come up with something, it's fun.)
And then of course, you have to assemble the words of your joke in
exactly the right order, ie as brief as you can get away with, usually with the "punch word" as close to the end as you can manage.
It's amazing how a really good joke can be completely screwed by even slightly rewording it. I don't think any other form of writing is quite so sensitive to word order, except possibly dialogue, where recasting a sentence can make the difference between convincing replication of speech and the famous "tin ear".