Thinking of the play itself, if Hamlet killed Claudius immediately the play would be over in one act. Hamlet's delay is the central issue of the play because it is what allows the play to go on. Hamlet's delay structures the play. In a sense, by delaying, Hamlet is taking part in writing the events; we might even say he is writing the play that we are watching/reading. Note that with the "Mousetrap," the play within the play, Hamlet must rewrite some of it in order to draw more similarity to Claudius' crime. Hamlet is literally rewriting the play within the play so that he might write/script Claudius's (and others') reactions.
We'll ha't tomorrow night. You could for a need study
a speech of some dozen or sixteen lines which I would set down
and insert in't, could ye not? (II.ii.517-19)
Hamlet wants to use the play to expose Claudius' guilt in the most dramatic way possible. Hamlet also delays killing Claudius when he is praying:
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.iv.76-79)
Each time Hamlet delays, he does so because he thinks his revenge will not be complete and/or that justice will not be fully satisfied. In delaying, Hamlet extends the drama and extends the play itself. His delay intensifies the anticipation. Hamlet's delay is driving force behind the rising intensity of the plot.
Hamlet could have done a few things to avoid so much tragedy. The problem is that Hamlet feels that he has no reason to trust anyone. Hamlet could have informed Ophelia the reason for his "madness." Then, she might not have become "mad" herself. If Hamlet tried to gain some allies during this revenge scheme, he might have had an easier time. But then again, in his mind, he could not trust his mother, nor his close friends. So, he relied only upon himself and this is why we have his famous soliloquies: the moments when he, alone, tries to decide what to do.