That Hamlet tells his treacherous friends Rosencrantz and Guildenstern "Denmark is a prison" (2.2.) indicates his feelings of aloneness and of having been betrayed by the ones he loves. Having been told by the ghost of his father that his brother Claudius has caused his death through poisoning as well as having been informed by his father's apparition that "that incestuous, that adulterate beast," his brother Claudius, has with "wicked wits and gifts" won his "most seeming virtuous queen," Hamlet, who has already been lamenting his mother's quick remarriage, places more blame upon his mother who he learns has married his father's murderer: "O pernicious woman!" (1.5).
Although the queen encourages Hamlet not to mourn so long for his father because "all that lives must die," Hamlet is inconsolable and feels that she has betrayed King Hamlet by marrying Claudius far too quickly.
...a beast that wants discourse of reason
Would have mourned longer--married with my uncle,
My father' brother....
...Within a month,
Ere yet the salt of most unrighteous tears
Had left the flushing in her galled eyes.(1.2.)
Queen Gertrude also is too easily influenced by the devious Polonius, whom Hamlet detests, thus weakening further her relationship with her son as he feels he cannot trust her. Likewise, Hamlet loses trust in Ophelia, who is manipulated by her father to the point that she imperils Hamlet's life. Obedient to her father despite her love for Hamlet, Ophelia tells him,
"...as you did command, I did repel his letters and denied his access to me" (2.2.180-110)
so when Hamlet receives these letters, he again feels isolated in his loyalties. So disappointed in Ophelia is Hamlet that his sense of loss mounts and his depression becomes insurmountable. Added to the betrayal of his mother and the deception of his old friends Rosencrantz and Guildenstern, the loss of Ophelia's love further plunges Hamlet into deep melancholy and brooding inaction.