In his play Hamlet, Shakespeare really only gives us one moment prior to the final scene in which Hamlet had an opportunity to kill King Claudius. That moment is in Act III, scene iii, and happens soon after Claudius has seen the play in which his murder is pantomimed.
In Act III, scene iii, Claudius informs Rosencrantz and Guildenstern that he is sending Hamlet to England and they are to supervise him. Claudius's purpose is to have England execute Hamlet. Later in this scene, when Claudius is alone, he delivers a monologue confessing his murder. He also kneels to pray to ask for forgiveness. It's while he is praying that Hamlet happens upon him and, since Claudius is alone and unaware of what's going on around him, sees it is an opportune moment to take his revenge, as we see in Hamlet's lines:
Now might I do it pat, now he is praying;
And now I'll do't. And so he goes to heaven;
And so am I revenged.
However, Hamlet stops himself because he reasons that if he kills Claudius after he has confessed his sins, then Claudius's spirit will go to heaven though Hamlet's own father's soul is in purgatory. Hence, the immediate reason why he hesitates is due to his religious convictions concerning forgiveness and damnation.
Why Hamlet hesitates to act is a very complex question, and many have thought up very different answers. However, like the immediate reason expressed in this scene, it can be argued that all of his hesitation relates to his religious convictions. We know from the reference to the fact that Hamlet is attending school in Wittenberg, Germany, that Hamlet is a Protestant, since Wittenberg was the seat of Martin Luther's Protestantism (I.ii.). Also of importance is the fact that seeking revenge is considered a significant sin in Protestantism; hence, in fulfilling the request of his father's spirit, Hamlet knows he is endangering his own soul with eternal damnation. He would not want to risk his own soul unless he was fully convinced of Claudius's guilt. Therefore, we can say that Hamlet's religious convictions are the primary reason why Hamlet does not act in revenge.