Actually, Hamlet doesn't want Claudius to know he knows the truth about Claudius killing his father. Hamlet, instead, pretends to be crazy to get Claudius off the track. However, Hamlet's own personal need to know if the ghost was really his father or a spirit sent by Satan meant to lure him into killing an innocent man leads Hamlet to reveal his hand. He does this by staging the Mousetrap play when the traveling actors come to court. He has them reenact the murder. Hamlet calculates that if Claudius responds in a guilty way, he will know the ghost was telling the truth.
Claudius does react in a way that shows he is guilty of the crime. However, Hamlet is now in a very dangerous situation. Claudius is not long going to tolerate Hamlet knowing his secret, so the prince's life is in danger. This danger increases when he kills Polonius. Claudius is not a fool; he knows that Hamlet mistook Polonius for him. Claudius feels he has to move fast before Hamlet can try to kill him again. This is why he ships Hamlet off to England with secret papers saying he should be killed as soon as he comes ashore.
In sum, Hamlet puts the need to know the truth ahead of his desire to keep Claudius from knowing that he knows his uncle is a murderer.