Answer:
Hamlet wants revenge for his father's murder. If he kills Claudius at the moment he's praying, Hamlet thinks, Claudius's soul will be pure and he'll be forgiven, and can therefore get into Heaven. King Hamlet died without a final confession/absolution/sacrament etc. and so his soul is wandering in Limbo. (I think that's the correct theological interpretation, but feel free to correct me if I have the doctrine wrong.)