Shakespeare uses several doppleganger characters in the play Hamlet: what does this accomplish?
In Shakespeare's Hamlet, the term generally used to refer to "doppelgängers" is "foil." A doppelgänger is...
...a ghostly double or counterpart of a living person.
A foil is defined as...
...[a] character that serves by contrast to highlight or emphasize opposing traits in another character.
In other words, a foil is a character that is very similar to another character in a story; however, the foil has distinct differences. Including these characters allows the reader the opportunity to put the similar characters side by side for purposes of comparison. By looking to how the characters are similar and different, the reader can obtain a clearer image of a specific character (in this case, Hamlet). There are several such foils in Hamlet.
First there is Polonius' son, Laertes. He is the son of the King's adviser. While his father spouts a great deal of wisdom (some of the best-known of Shakespeare's quotes), he is not a man of wisdom at all. However, Laertes, like Hamlet, is dedicated to his father. When Hamlet learns from the Ghost that Old Hamlet was murdered, he wants nothing more than to avenge his father's death.
Laertes is the same: when he learns of his father's murder, he wants nothing more than to avenge his father's death. The difference between the two is that Laertes takes immediate steps to do so, however he is unethical and immoral in achieving his ends, cheating during a friendly sword fight to kill Hamlet rather than collecting the facts. He cares nothing for acting honorably: he only wants revenge, at any cost, under any circumstances:
What would you undertake
To show yourself your father's son in deed
More than in words?
To cut his throat i' the church. (IV.vii.135-138)
However, just before Laertes delivers the fatal blow, we can see that his anger has gotten the better of his good judgment, and that perhaps he is much more like Hamlet in this way. He notes:
And yet it is almost against my conscience. (V.ii.301)
Next is Young Fortinbras—also a foil to Hamlet. Old Hamlet killed his father Old Fortinbras in battle—in a fair fight. Young Fortinbras also takes immediate steps to avenge his father's death by preparing to attack Elsinore Castle. However, his uncle steps in, corrects him for his erroneous behavior, and as a nobleman's son, he gracefully accepts the truth of his father's death and turns his attentions to attacking Poland. He is a man of good character and honor.
Hamlet, however, does not act right away. We might excuse him because he is not sure if the Old Ghost is his father or an evil spirit trying to rob him of his soul by convincing him to kill King Claudius, a mortal sin. Instead, Hamlet sneaks about looking for proof of the Ghost's accusations. In doing so, Hamlet trusts no one, including his mother and his sweetheart, Ophelia. While Young Fortinbras listened to what his uncle had to say and could be reasoned with, Hamlet cannot do so. He does not trust anyone around him—not even the woman he loves (a mistake), and in this distrust, along with the extended time he takes to act, all those he loves (and he also) end up dead.
In comparing Hamlet to his foils, we see Hamlet more clearly—both his strengths and weaknesses. We can more clearly understand his dilemma in wanting to do right by his father, but can also see steps he might have taken to prevent the deaths of others and himself.