Hamlet while talking to his father's ghost was urged to avenge the foul murder, but to leave his mother out of it as her guilt would be punishment enough. The ghost told him to "revenge his foul and most unnatural murder. Leave her to heaven and to those thorns that in her bosom lodge, to prick and sting her" (1.5.51). The ghost of the previous king gave Hamlet the solution that he needed. The ghost as well beseeched Hamlet to "let not the royal bed of Denmark be a couch for luxury and damned incest"(1.5.53). Hamlet was required to not only restore his honor, but to restore the honor of all Denmark as well. The burden upon his shoulders caused him to clear from his mind all but what was necessary to solve his dilemma. This allowed him to think in a rational and sane manner. Ironically, for Hamlet to complete his task of avenging his father's murder, he played the role of being mad.
In theory, Hamlet could have killed Claudius while feigning insanity. Thus, he would escape estrangement, because his people would blame his action on his insanity, not on malicious intent. He does not do this, however, because he is subconsciously inhibited from deliberately killing Claudius for two reasons. Religion was the first reason; more importantly not having enough facts that Claudius truly killed his father. Only having the word of a ghost was not enough, in addition it could have been sent from the devil. To be sure, Hamlet staged a clever play, which a sane and genius person would create, to catch Claudius once and for all. Claudius expressed a reaction of guilt, Hamlet got the answer, that in fact Claudius did kill Old Hamlet. .
Following the play, Hamlet meets with his mother. There he lunges at Polonius, thinking that the person behind the curtain might have been Claudius. Although in front of his mother he does not "know" who is behind the curtain and thus, had he killed Claudius, he could not have done so deliberately.