I think there is a misplaced speech in Hamlet which has resulted in much unnecessary confusion. You'll remember that in Act I Hamlet meets his father's ghost, who tells his son that he was murdered by Claudius. Hamlet is full of resolve to do the right thing, but he makes no attempt to kill Claudius until Act III, Scene IV. (That attempt is frustrated when he mistakenly believes Claudius is praying.)
Why does Hamlet wait so long to act? Or, rather, to attempt to act? The answer lies in what has happened just before the attempt--the staging of the play within the play during which Claudius, seeing enacted a murder similar to the one of which he is guilty, calls out for lights. At that point, Hamlet knows Claudius is guilty.
So if that's when he knows Claudius is guilty, then he mustn't have known it before, right?
The key speech is in Act II, Scene II. In a soliloquy, Hamlet says, "...The spirit that I have seen/May be the devil: and the devil hath power/To 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..."
In other words, Hamlet isn't sure the ghost is that of his father pricking him to take a just vengeance. It could be the devil trying to trick him into murder. So the play-within-the-play is a device to not only reveal Claudius's heart, but to test the ghost's veracity.
I think a lot of the confusion that has been whipped up over Hamlet--including all the nonsense about his supposed inaction--is because Shakespeare didn't plant the dramatic idea of Hamlet's doubts of the ghost's veracity at the right place. If it had been placed right after