Hamlet's delay or his indecision is one of the most debated aspects of the play. In general, Hamlet delays killing Claudius because he is a thinker rather than a doer. Hamlet is a wordsmith more than a sword-smith. His grief does not prevent him from killing Claudius. One could argue, that at his young age, he is an idealist and therefore he must find the most ideal and dramatic way in which to carry out his revenge. The external issue is that killing a king is a big deal and it can have political and spiritual ramifications. But in the end, Hamlet's delay has to do with his own psychological state. He delays because he over-thinks everything. His tendency to frame every act in terms of its moral and philosophical significance and impact is what leads to his great soliloquies and subsequently delays his actions.
In the "Prayer Scene" in Act 3, Scene 3, Hamlet seems ready to kill Claudius but he stops because Claudius is praying. Hamlet doesn't feel that killing a praying man (whose soul would go to heaven) is punishment enough.
A villain kills my father, and for that
I, his sole son, do this same villain send
O, this is hire and salary, not revenge! (III.iii.76-79)
This scene follows the "play within a play" where Hamlet intended to "catch the conscience of the king." Since Hamlet could not catch Claudius in the act of killing his father, he has resolved himself to catch and kill Claudius when his crime and/or his guilt is apparent. Ironically, Claudius is aware of his guilt and expresses it in the prayer scene:
O, my offence is rank! It smells to heaven.
It hath the primal eldest curse upon't,
A brother's murder. Pray I can not. (III.iii.36-38)
Claudius can not pray. Hamlet has missed his opportunity to kill Claudius in a moment of guilt, not prayer. This shows that Hamlet feels he has to catch Claudius in an overt, or even public, expression of his guilt.
When Hamlet mistakes Polonius for Claudius, he does go through with the killing. But note that Polonius is behind a curtain. Hamlet believed that he had caught Claudius in a conspiring, guilty act. Hamlet finally stabs Claudius in Act 5, Scene 2 when the "villainy" is discovered that Claudius had poisoned the cup from which Gertrude drank. (Claudius' plan B was for Hamlet to drink from the cup.) Having finally caught Claudius in sin, in full public view, Hamlet no longer delays.
One could attribute this delay to Hamlet's personal inadequacy. In the "to be or not to be" soliloquy, Hamlet says, "Thus conscience does make cowards of us all," (III.i.85). He is aware that his conscience implores him to kill only at the most appropriate time. But where Hamlet is inadequate in terms of acting spontaneously, he is superior in moral and logical reasoning. It is his reason that compels him to set up the perfect situation of avenging his father. It must be perfect to satisfy Hamlet's needs to have Claudius killed when his (Claudius') guilt is clear to Hamlet, Claudius, and ideally, to the public.