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.