People build censors against things which are forbidden. This list of forbidden things includes stupidity; adults are not allowed to do stupid things. Not knowing things is therefore censored. If a person reaches a point at which his brain state is that of something censored, and there are no alternatives, they become confused, and find it humorous. (the brain triggering humor is a way from keeping the mind from being hostile toward the rest of the world) This laughter allows the brain to take it's time in making connections.
People tend to find new things difficult to understand. This may be related to the fact that they do not yet posses useful frames for the given object or situation. One method of dealing with this is to learn what is needed to create the frame. On the other hand, this is a slow and difficult task, and often the new situation is so strange as to defy belief. In this case, many people will choose to laugh at the new situation.
This can be seen in many people faced with new and different cultures. Quite frequently they will laugh at the culture which is different that their own. This is because it is strange and different, and it is easier to laugh than to admit that the other culture posesses knowlede that their own does not. (Of course their own understands things that the other does not, but that is much easier to admit) So these immigrants with different customs and cultures are the butt of jokes. However, as time passes, and more is learned, these jokes will become less funny as their topics become more and more familiar, and the frame required to make them funny fades.
At the other end of the scale, puns are funny because they allow people to be what they aren't, and to be what they are not allowed to be. Puns may seem to be the exception to the "funny things are forbidden or bad" rule, but in reality, they are not. A pun is merely the situation in which the person involved shows herself as stupid. Because the person telling the pun is not taking himself seriously, no one else will take him seriously, and so he need not be censored for his forbidden remarks.
People want to laugh. Laughter gives a connection between people, and suggests that communication has been successful, as both people have managed to build frames describing some situation, and both people have similar enough frames that both find it funny. Communication is a very good way to keep from killing one another. In addition, when someone is laughing, his motor skills are impaired, so he cannot kill you. Thus, humor can be used as a way to diffuse danger.