When the troupe of actors comes to Elsinore and Hamlet begins to conceive of his plan to have them act out a play that is similar in its plot to the way his father was killed by his uncle (or so a ghost in the shape of his father would have him believe), Hamlet reveals one psychological reason why he has not acted on the ghost's charge to exact revenge so far: doubt. He says,
I'll observe [my uncle's] looks
I'll tent him to the quick. If he do blench,
I know my course. The spirit that I have seen
May be a devil, and the devil hath power
T' assume a pleasing shape (Act II, Scene 2, lines 625-629).
Hamlet worries that the spirit he saw on the ramparts was not actually his father. It is possible that the ghost is not really the spirit of his father at all and that it is actually the devil, come to persuade Hamlet to do something evil and so ruin his own soul in the process. If he can get Claudius to reveal his guilt, then Hamlet will know for sure that he was his father's killer, eliminate all his doubts, and allow him to move forward with his revenge. This is why he orders this play to be performed and why he keeps such a close eye on his uncle the whole time.