Note to Hamlet, 5.1.90-91: "Here's fine revolution, and we had the trick to see't."
Hamlet is using heavy irony.
Hamlet and Horatio are observing the gravedigger's rude treatment of a skull which might have once belonged to a courtier who knew how to beg with flattery. Hamlet is saying that the courtier's change of fortune, from being alive to being dead, is actually a good thing, if only we could realize it. Perhaps he is making a silent comparison between the courtier and King Claudius, whose death would make the world a better place.