When at first something seems badly wrong, and all of a sudden it turns out that it is really okay, one frequently laughs. This may be called ``relief laughter''. For example, I once opened a refrigerator door so quickly that a quart-sized milk container fell out of the door onto the floor. When, after it hit the ground, I realized that it was an unopened container and wouldn't spill anything, I laughed. This is relief laughter.
The essential humor in peekaboo is relief laughter. Babies go through a stage when they are highly amused by the game of peekaboo. In peekaboo, an older person (the peeker) brings the baby's attention to their face, and then hides their face behind their hands. Then, pulling their hands away, the peeker's face becomes visible again. Hiding, revealing, hiding and revealing one's face with one's hands or by hiding behind some other opaque object constitutes the funny game of peekaboo; the moment of (peak) laughter is generally the moment of reappearance.
Now, children at this early age are learning about object permanence, for which there are three logically distinct stages. In the first stage, objects that cannot be perceived aren't understood to exist at all. In the second stage, objects that can no longer be perceived are thought to have gone out of existence. This is distinct from the first stage, where if something moves out of the field of view, it seems never to have existed in the first place. In the second stage, there is enough of a sense of object permanence to realize that the missing object once existed, but not enough to realize that, despite being out of the field of view, it still exists. In the third stage, of course, the object that disappears is understood not to have gone out of existence.
Suppose a baby cries when its mother leaves the room, thinking that its mother has gone out of existence. This could only occur if it remembers that the mother previously did exist (stage 2). At an earlier stage, the baby doesn't appear to notice that its mother ever did exist. And at a later stage, it isn't the same kind of violation because the mother still exists despite her absence.
We can explain the intrinsic humor of peekaboo in the light of this discussion. After stage three, when a child knows about object permanence, it counts as no violation of the existence of treasured entities like parents and siblings and whatnot when those entities leave the field of view, because they have not ceased to exist. However, during the development of object permanence, but before it is mastered -- at stage two -- the very existence of things can be violated by their departure from view. Because of babies' affective attachment to things in their worlds, it is a violation of the way things ought to be when they blink out of existence, and it is a relief to laugh at when they reappear and the violation is undone.
How might peekaboo seem not to be funny? The 3-level scale helps here. Some entities are too important to be lost, and when Mamá leaves the room, a baby may break down and cry. This is no joke, because a baby's emotional attachment to the existence of their mother is so strong that violating that principle is truly frightening. Peekaboo can also result in crying rather than laughing if the disappearance phase lasts too long. These both represent higher degrees of violation, and they change the nature of the response from laughter to some kind of distress. On the other hand, the intensity of the violation can be decreased, also, resulting in lack of perceived humor. For example, after object permanence is mastered, a child may no longer infer non-existence from disappearance, so that no personally important principle of continuing existence is violated, and without such a violation, there is no humor. In fact, however, peekaboo is a game that becomes elaborated and modified from its earliest developmental forms (Fernald & O'Neill 1993), becoming somewhat similar to hide-and-seek. As the game becomes an established and increasingly elaborated form, the essential humor -- relief laughter that occurs upon reestablishment of the existence of a valued entity that had disappeared -- is replaced by other kinds of pleasurable dynamics. But according to this argument, the intrinsic humor at the earliest stage is a form of relief laughter due to stage 2 in the development of object permanence.