How does Hamlet relate to the theme of isolation?
Hamlet is basically isolated from everyone at the court. The only real friend he can trust is Horatio. Even Hamlet's own mother has married his uncle and Hamlet does not really know her degree of involvement, if any, in his father's death.
Ophelia is too close to her father, Polonius, to be trusted. After all, all Polonius has to do is tell her not to see Hamlet and she obeys him. This sense of isolation must lead to both desperation and depression for Hamlet, who is trying to find out the truth about his father's death before he does anything.
After the play, "The Mousetrap," Hamlet discovers what he thinks is the truth but he is still alone in his search for revenge. Horatio can listen, but he is not a member of the royal family, and therefore has no real power to help Hamlet. Then he is sent to England with Rosencranz and Guildenstern, two so-called friends that he does not trust. His suspicions are confirmed once he gets ahold of the letter Claudius is sending to the King of England, asking the English king to execute Hamlet.
He returns to Denmark, only to find Ophelia dead, Laertes his enemy and still only Horatio to confide in. His sense of isolation must be almost total towards the end of the play. I think that is one of the reasons he accepts whatever fate has planned for him during the sword fight with Laertes. Even if he had survived the sword fight and Fortinbras' challenge, life as the King of Denmark would have made him even more isolated than before because leadership by itself is isolating.
As the other answers indicate, Hamlet is both alienated from the Danish court and trapped within his own depressed psyche.
His father's death has affected him deeply. Others, such as his mother, have bounced back from the loss quickly. This leaves feeling him isolated, alienated, and alone. He can't fully grasp why everyone else's world hasn't stopped the way his has. How can people go on eating, drinking, and living life as if his father hasn't died? They, in turn, can't understand why he is drooping around and can't seem to snap out of it.
The appearance of the ghost increases Hamlet's isolation. His distrust of everyone around him is suddenly dramatically heightened by the ghost's words. He understands himself to be living in a cancerous cesspool of corruption, where nothing is as it seems. He contemplates and rejects suicide as a means of escape from an existence that seems increasingly unbearable. Because of his interiority, he is sometimes called the first modern hero.
Hamlet enters into a vicious cycle of isolation. The more erratically he behaves, the more he pushes other people away. The more he pushes others away, such as Ophelia, the more isolated he becomes. Yet this isolation gives him a chance to ponder, to evaluate, and to analyze his situation, not simply to react as Laertes does when his father is killed.
Hamlet is a very intellectual play that concerns itself with questions of the mind, in particular whether or not Hamlet is sane or not.
The mind itself is an isolating concept.
Hamlet, who is either feigning madness or is has actually become insane, is literally trapped in his thoughts and this is beautifully expressed in his 'To be or not to be' soliloquy. His thoughts caputre and imprison him, which also explains Hamlet's inability to act out his revenge straight away.
Ophelia, a character who undoubtably goes mad, is another example of how one becomes trapped in their mind and is physically isolated from the court before she is removed from life itself through death.
Another character study in isolation would be Claudius. His guilt for the murder of his brother is often on his mind, and Claudius reveals his feelings of isolation when he confesses to God that he is a murderer. He alone knows the truth of the murder (or so he thinks) and as such, he suffers alone.
All three of these characters suffer major psychological issues which cause them to become prisoners unto themselves, each one trapped in their own mental states.