Why does Hamlet hesitate over whether or not he should kill the king, his uncle Claudius?
Several things probably keep Hamlet from "doing the deed."
1. What Hamlet says is he doesn't want Claudius, the murderer of his father, to have more preparation for death than Claudius allowed King Hamlet. The Ghost reveals to Hamlet that he died with his sins unconfessed; Hamlet is reluctant to kill Claudius as he is confessing. That would not be the purest form of revenge. The irony is, of course, that Claudius is not actually confessing his sins, so it might have been a perfect time for action.
2. Hamlet also says he would rather "catch" him doing something else when he chooses to take his revenge. He knows Claudius is a man of the flesh, and if he catches him in some frivolous or lustful pursuit Claudius will most certainly meet his demise in a sinful condition.
There are several other, more human nature kinds of considerations which may have prompted Hamlet to hold back his hand of revenge when presented with the opportunity.
3. Hamlet is reluctant throughout the play and has demonstrated his ability to be--at least to some degree--a man of no action. He is all hyped up for revenge, yet he has to check and re-check and ask a friend (Horatio) to bolster his certainty that the words of the Ghost were not a lie.
4. Hamlet is not God, and taking a life is a mortal sin according to his religion. Eternal personal damnation would, I think, give one pause.
5. Hamlet is as certain as one can be by the time he sees Claudius alone with this opportunity in front of him, yet he has to be wondering how he would live with himself if he killed his uncle and then found out he was wrong.
6. Revenge is always sweeter, they say, when the person who has done the wrong knows he's being repaid for his crime. That might have happened in this particular scenario, though it's not likely unless Hamlet told on himself. The more public end to Claudius, though unplanned, is much more gratifying, for then all knew of his perfidy and crime.
Hamlet could but does not exact his revenge at this moment in the play; this choice determines nearly everyone else's fate, including his own.
Hamlet, in Shakespeare's Hamlet, tells you himself why he hesitates to kill Claudius:
Now might I do it pat, now 'a is a-praying,
And now I'll do't--and so 'a goes to heaven,
And so am I revenged. That would be scanned [looked at or thought about again].
A villain kills my father, and for that,
I, his sole son, do this same villain send
Why, this is hire and salary, not revenge. (Act 3.4.73-79)
Hamlet's Catholic beliefs suggest that if Claudius dies just after he's confessed, he will be forgiven of all of his sins and he will go to heaven. Hamlet doesn't want to send Claudius to heaven.
Hamlet's father, in the form of the Ghost, is lingering in a purgatory-like state, and Hamlet, if he were to kill a king, may go straight to hell. Thus, Hamlet reasons, Claudius, the evil one of the three, will be the only one of the three to be rewarded with eternal salvation if he kills Claudius while he is confessing.
Ironically, Claudius, while he is praying, is not really confessing. He is unwilling to give up the benefits of his sin, and therefore does not confess or repent. Hamlet could have killed Claudius while Claudius was praying, and order would have been restored in Denmark, presumably.
This makes Hamlet's decision to walk away and to not kill Claudius the climax of the play. Hamlet is guilty of hubris, attempting to rise above his station in life. Salvation is God's business, not Hamlet's. Hamlet is playing God when he attempts to determine another human's eternal salvation. The terrible loss of so many lives after Hamlet decides not to kill Claudius could have been avoided.
To add to the previous post, Hamlet delays for other reasons as well:
1. He is a very moral individual. He must make doubly sure that Claudius is actually guilty. The act he is considering is regicide and to some extent patricide. Hamlet knows the gravity of this action. Killing a king and a stepfather is not something to be done without thought. This type of consideration sets him apart from Laertes who is quite rash and foolhardy in his attempts to avenge his father's murder.
2. Claudius is very powerful, and very smart. Hamlet knows he will have only one chance to kill the king. If he should fail, the consequences will be severe. When Hamlet does take action, he makes a dreadful mistake--klling Polonius instead of Claudius. From that point on, Hamlet is on the defense and has no opportunity until Act 5 to exact his revenge. Hamlet's caution sets him apart from Fortinbras who is easily foiled in his attempts to avenge his father's death by his uncle and Claudius.