Hamlet spews out nihilistic conceits in 4.2. and 4.3., and continues to indulge in gallows humor in 5.1. until he wakes up to a new perspective toward afterlife while meditating on Yorick's skull. Since he pretty much moped around in suicidal thoughts, his awakening in 4.4 and 5.1 is so swift and surprising. Now Hamlet is ready to think and act like a king, even though he turns out to be a king we could have had but did not. At this point, the vulgarity, puns, and gallows humor are reassigned to the two grave diggers and one of them, the First Clown, seems to serve as the conventional fool who speaks out to the king (or prince).
First Clown argues that Adam was the first grave digger and grave digging is a noble profession because Adam had (a coat of) arms. Second Clown contends it only to receive an answer that Adam dug with his arms. Here "arms" serves as a pun.
These menial workers further undermine the arbitrary division of class by observing that a gallows maker builds the most durable monument in human history. It is not much different than saying all humans are common criminals and crooks. Hamlet's misanthropic rants seem to echo through the grave diggers' mouths.
No more wading through self-hatred and nihilism, Hamlet banters with the grave digger and plays on the word, "lie." At the beginning, they both use "lie" to mean "stay," but soon its meaning changes and now both start to use it in term of "being laid in the grave." Since both are alive, neither can claim the grave as his and each man starts to accuse the other of lying. This pun introduces a comic relief to the play and also alerts the viewer's attention to the owner of the grave--Ophelia.