In Shakespeare's Hamlet, Hamlet’s behavior is a function of his circumstances and his related decisions.
At the start of the play, Hamlet (and the rest of Denmark) believes that Old Hamlet died when he was stung by a poisonous snake while sleeping. Hamlet is devastated by his father's death and his mother's hasty remarriage to Hamlet's uncle Claudius (Old Hamlet's brother). However, there is nothing to indicate that Hamlet is at all suspicious about his father's death. Old Hamlet made a habit of napping in the same place, at the same time each day, unattended.
Hamlet's decisions are the result of his circumstances. If the Ghost and Hamlet had never spoken, Hamlet (we can assume) would have continued on with his life. He had not been named king upon his father's death, ostensibly because he was young and did not have the experience with state matters that Claudius did. While Ophelia was not suitable to marry Hamlet (or so Polonius and Laertes believed), it is not impossible to imagine that Hamlet, having a strong will of his own, might have continued to woo Ophelia and marry her, becoming King of Denmark after his uncle's passing.
However, everything is changed with the appearance of the Ghost. When Hamlet speaks to the Ghost in Act One, scene five, the spirit informs him of his uncle's murderous actions. From this moment on, Hamlet's behavior is governed by the decisions he must make because of his new circumstances. Learning of Claudius' duplicity and the assassination of his brother, Hamlet is called upon by the Ghost to avenge Old Hamlet's death. Nearing the end of the scene, Hamlet recognizes the man his uncle truly is (a "villain"), and he declares that he will be faithful to the requests of his father's spirit.
O villain, villain, smiling, damned villain!
My tables—meet it is I set it down
That one may smile, and smile, and be a villain;
At least I am sure it may be so in Denmark.
So, uncle, there you are. Now to my word:
It is ‘Adieu, adieu! Remember me.’
I have sworn't. (111-117)
Hamlet, in order to carry out his father's command, must find a way to take Claudius' life. Claudius is a cunning and intelligent adversary. At the same time, however, Hamlet is now forewarned that Claudius hides the truth with a smile, a mask that covers up the man's true character. (This supports the theme of appearance vs. reality, something also seen in Hamlet's appearance of madness.)
Hamlet knows he must be cautious because (as the Elizabethans believed) killing a king was a mortal sin, damning the culprit's eternal soul. Hamlet's decisions will (from here, on) be the result of his newly revealed circumstances. One of Hamlet's primary concerns must first be to ascertain that the Ghost is "honest," and not sent by the devil to trick him into sacrificing his soul after death to an eternity of torment. Hamlet needs proof.
Hamlet begins to plan before he leaves the battlements. He tells Horatio not to be surprised when he sees Hamlet acting crazy, for while everyone will believe the young prince's grief over the loss of his father is the cause for his seeming insanity, Hamlet explains to his friend that his is the only way he can go about proving Claudius' guilt without raising the King's suspicions. This is Hamlet's second major preoccupation.
As I perchance hereafter shall think meet
To put an antic disposition on (191-192)
Hamlet's "antic disposition" (insane behavior) will be blamed on his grief. Claudius will, therefore, not be surprised as Hamlet travels about the castle, seemingly mad—while the entire time Hamlet is actually listening, watching and calculating his next move. In realizing he cannot trust Claudius, Hamlet realizes he must be extremely careful of almost everyone else. He had not suspected his uncle before: how many others in his uncle's court must he also be wary of?
Unfortunately, in all of his machinations, Hamlet will alienate Ophelia to the point of her madness, and will mistakenly kill Polonius. As a side note, Laertes is a character—much like Hamlet—whose circumstances drive his decisions: first with his father's death and then with Ophelia's death, thereby altering his usual behavior.
Hamlet's behavior is driven by his decisions, which come into play based upon his change in circumstances. His circumstances force Hamlet to make specific decisions in answer to what Claudius has done. In the long run, almost everyone Hamlet cares about (and he) will die because of Claudius' original crime. And with Claudius' decisions, Hamlet's behavior becomes the function of his changed circumstances and related decisions.