The grave differs scene is one of the most important in the play because it is here that Hamlet's ever-developing views on mortality really materialize.
In the gravedigger scene, Hamlet wonders outloud to Horatio why the gravediggers are casually throwing bones around. He realizes that those bones may have once belonged to important people. When Yorrick's skull is thrown out of he grave, Hamlet has a personal reaction for he knew Yorrick as a child.
The person who used to joke with him, the clown jester that Hamlet kissed as a child, has no been reduced to a jawless skull. Hamlet asks Horatio if Caesar was like that. When Horatio says that he is, Hamlet realizes that no matter how important one person may think themselves to be, eventually they are reduced to nothing.
Death is the true equalizer. It doesn't matter your rank or importance. Once you are dead, nothing remains.
The next time we see Hamlet, he is ready to face death if that is what his fate is. Without the gravedigger scene, Hamlet may have not experienced such development in his character.
To take off on the above post. What Hamlet realizes is that though we all reduce to dirt (as opposed to dew) it is memory that allows us to live on after death. The memory of Yorick holds a special place for Hamlet even though he was just the king's servant. Great men like Alexander and Julius Caesar live on in our collective memories. They have histories written about them. They have plays and stories written about them like Julius Caesar who, coincidentally, had a play written about him by Will Shakespeare. It may be playing down the street, go see it. Or like the hellish Pyrrhus whose history is not so favorable.
Any way by the time Hamlet lays dying in the next scene, Hamlet is begging Horatio to make a special effort to have him memorialized. Horatio, eager to tell the story, directs that it be presently performed. Hamlet is then carried to the stage where he has been performed for over 400 years.