Rosencrantz and Guildenstern's arrival at Elsinore represents the duplicity of Claudius and even Gertrude to a certain extent. They have been sent for as a means for the King and Queen to find out what is wrong with Hamlet. While it can be stated that the Queen has genuine concern for her son, King Claudius is just worried about how Hamlet's behavior is going to affect his reign as king. That they would call up two friends of Hamlet's, butter them up by telling them that they are Hamlet's closest childhood friends and with a promise of "a king's remembrance" (meaning money), the King and Queen have brought in two people whose loyalty is first to Claudius and second to Hamlet. Hamlet can't trust these two, and he figures that out pretty quickly. It is such a sad scene when he at first asks them if they were sent for and eventually pleads with them to tell the truth. They only do so when they realize they have no choice. These characters are representative of how isolated Hamlet is and how wary he must be to preserve himself in this dangerous place.
The Players provide a means for Hamlet to "catch the conscience of the King." By enacting a play that is altered enough to mimic the poisoning of King Hamlet, Hamlet hopes that Claudius will react in a guilt-revealing way and then Hamlet will be completely justified to enact his revenge. Hamlet's interations with them also reveal another side of Hamlet is familiar with the theatre and who appreciates fine acting -- something that is trying to accomplish with his acting crazy around the castle.
The grave-diggers provide some comic relief at the start of Act 5, but they also provide an opportunity for Hamlet to come face to face with death. He comes to realize that death is the great equalizer and will come to everyone. The more real death is for Hamlet, the less he fears it and all of his actions. Facing death makes him more ready to take the actions that he must in order to fulfill the revenge request from his father.
While these minor characters don't have a lot of interconnection, the play would be sorely lacking without them.
I will start with the players. They become important since they are the vehicle by which Hamlet is able to confirm to his own satisfaction, what he was told by the ghost. By having them reenact the murder described to him by the ghost of his father, he sees Claudius's guilt. Without their performance, Hamlet would not be certain of his uncle's guilt.
Rosencrantz and Guildenstern are school friends. They are being used by Claudius to find out what is wrong with Hamlet. They also provide some comic relief. It doesn't take long for Hamlet to figure out the purpose of their visit.
As for the grave diggers, they also serve as comic relief plus they also provides us with Hamlet's age.
Ingeniously, Shakespeare has used several of these characters to lighten things up.
As Hamlet interacts with each of these groups, much about his character is revealed. Through Rosencrantz and Guildenstern, we realize how perceptive Hamlet is in detecting and eluding traps that are set for him. Acting as spies for Claudius, Rosencrantz and Guildenstern try to pump Hamlet for information about his reasons for his madness in Act 2 and his motives for the play-within-a-play in Act 3. In each Hamlet quickly understands the nature of their questioning and tells them that he cannot be played. In fact, he is able to sabotage the "engineer with his own petard" and arrange for the spies to be killed rather than him. Ronsecrantz and Guildenstern fit nicely into the spying motif that is pervasive in the play.
With the players, we see Hamlet as a young man well versed in drama. He is able to recite a lengthy speech from a monologue he remembered and can give instructions to the players as to how to act. This makes Hamlet's creation of the Mousetrap all the more credible. The players also are representative of the acting motif in the play.
The Grave-diggers highlight Hamlet's ability to converse with the commoners. He delights in their humor and is able to quip with them. We see why Claudius was so intiminated by Hamlet's popularity with the people. The grave-diggers also help develop the theme of death in the play, as they are quite explicit about the physical effects of death--an aspect of death that Hamlet has not fully explored. They are a comic introduction to Hamlet's more profound musings about Yorick and his skull. Their callousness toward the graves they are digging provide a sharp contrast to Hamlet's highly emotional and intensely personal response to Ophelia's funeral.
There is much in the plot of Hamlet that highlights proper behaviour for one's station in life, especially if you are of the royal family. Gertrude and Claudius chastise Hamlet for his very un-correct display of grief in the very public Act I, scene ii and Polonius not only lectures Laertes about proper behaviour, but has him spied on to ensure that he is behaving as a man of his position should.
So, one of the importances of R&G is to demonstrate the "proper" way Hamlet should be behaving. We can assume that they are very close in age and station to Hamlet, and they do whatever the king says, even strong-arming Hamlet out of Denmark as a part of a plot to end his life. All in allegiance to their king. Acting out of blind allegiance is the last thing Hamlet would do.
As for the players, part of their purpose is to highlight Hamlet's inability to act on his feelings. When he comments that one player is able to create (from his imagination) all the proper behaviour for nothing,
What's Hecuba to him or he to her
That he should weep for her? What would he do
Had he the motive and the cue for passion
That I have?...
A dull and muddy-mettled rascal, peak
Like John-a-dreams, unpregnant of my cause
And can say nothing.
he calls attention to his own inability to act. So, Hamlet is being shown up by a player, whose apparent ability to act and follow through on his emotional impulses is all for something made-up, while Hamlet, with a real and important call to action can do nothing.
And finally, the Gravediggers are also in the play to provide a dramatic passage of time and to re-introduce Hamlet to the audience, who has been absent from the play for a few scenes. Time has passed, and the clowns help show that to the audience by answering Hamlet's questions at Ophelia's grave.