These questions have been debated for centuries. They are called "The Hamlet Problem." I think the best answer was given by Samuel Taylor Coleridge, who said Hamlet procrastinates because he thinks too much. When he acts on impulse, he can act very courageously. A good example is the way he is the first to board the pirate ship which kidnaps him. When Hamlet finally kills Claudius, it is impulsively, in the heat of emotion. He doesn't have time to think about it. He holds the poisoned foil right in his hand.
When Hamlet is on his way to England, he discovers his escorts Rosencrantz and Guildenstern are carrying a letter asking the English king to have him executed immediately upon arrival. Hamlet forges a substitute letter in which he has Claudius asking the English king to execute Rosencrantz and Guildenstern. This is before Hamlet is kidnapped by the pirates and then ransomed in Denmark by Horatio. At that point, Hamlet knows his life is in extreme danger because Claudius will soon receive word from England that Rosencrantz and Guildenstern have been beheaded. Claudius will know Hamlet forged a new letter and will certainly have Hamlet executed as a punishment and for the king's own self-protection. The following dialogue shows this.
It must be shortly known to him from England
What is the issue of the business there.
It will be short. The interim is mine.
Hamlet knows he must kill Claudius without further deliberation or Claudius will have him killed. He does not know Claudius has already made plans to have him killed in the forthcoming fencing match with Laertes.
Hamlet had other reasons for his previous delays. One was that he sincerely believed the ghost he met in Act I, Scenes 4 and 5 might be a devil instead of his father. In Act II, Scene 2 he says to himself:
The spirit that I have seen
May be a devil; and the devil hath power
T' assume a pleasing shape; yea, and perhaps
Out of my weakness and my melancholy,
As he is very potent with such spirits,
Abuses me to damn me. I'll have grounds
More relative than this. The play's the thing
Wherein I'll catch the conscience of the King.
Hamlet had to stage the play-within-a-play to prove to himself that Claudius was actually guilty, as the ghost had told him. After that, he felt free to act against the king, but he was forestalled by being sent to England as an ambassador.
One other reason Hamlet might have been slow in carrying out his obligation to kill Claudius is that Hamlet is aware he is supposed to inherit the throne when his uncle dies. All he has to do is wait. If he kills Claudius, it might be impossible for Hamlet to inherit the throne, especially if everyone believes he is mad. They would think Hamlet was motivated purely by ambition and would not believe Claudius murdered Hamlet's father in order to usurp the throne and marry King Hamlet's wife Gertrude. As a result, Hamlet is torn between acting and waiting for the crown to drop into his lap.