The humor in Hamlet is dark. This fits the play's grim theme of depicting Denmark as a corrupt kingdom.
Most of the play's often sharp-edged humor comes from Hamlet himself. It serves as a commentary on what Hamlet perceives is occurring, and it helps characterize Hamlet and others in the court.
Hamlet's wit shows through his wordplay. He especially likes puns. For example, in the play's opening, he states that his mother and Claudius are
a little more than kin, and less than kind.
Here he saying that he and Claudius have become more than kin or mere relatives now that Claudius has married his mother and become his stepfather. He puns three times on the word kind, which means kin in the sense of "the same kind," which means "natural," and which means "considerate" or "kindly" as we would understand the term today. By stating, as an aside, that Claudius is less than kind, Hamlet is saying his uncle is not of his kind or tribe, that his marriage with his brother's wife is unnatural, and his uncle is less than considerate. Along with Hamlet's other utterances comparing his uncle unfavorably with his father, this witticism helps us understand Hamlet and the churning anger that motivates him.
Hamlet also uses dark, some might even say, cruel humor when he speaks with Ophelia with sexual innuendo. Her confusion helps characterize her as innocent, while we can see Hamlet's anger at his mother spilling over into his treatment of Ophelia. For example, before the Mousetrap play, he asks Ophelia if he can "lie" in her lap, a sexual innuendo, and when he tells her to go to a "nunnery," he is making a cruel pun on a word that meant both convent and brothel at the time. Most women would not appreciate their boyfriends telling them to become a prostitute.
Hamlet's humor shows the contempt he feels towards courtiers such as Polonius, Rosencrantz, and Guildenstern for what he considers their sponging, exploitative behavior towards him. It also foreshadows the danger these commoners are in for "playing" with a prince. Their confusion shows their cluelessness, though Polonius does realize that there's "method [a logic]" in Hamlet's "madness."
You can find many, many examples of Hamlet's dark humor, but the main point is that it gives us additional information about his thoughts and about other characters. It is also notable that there is little to no lighthearted humor in the play.