In Act I, Scene 5, a ghost appears to Hamlet--it is the spirit of Hamlet's father. The ghost indicates that he has been sent to purgatory to be "purged" of the sins he committed during his life: "I am thy father's spirit,/Doomed for a certain term to walk the night,/And for the day confined to fast in fires/Till the foul crimes done in my days of nature/Are burnt and purged away." (lines 9-13)
Purgatory is a teaching of the Roman Catholic Church, where they believe the soul is sent to be purified. Once the king has been purged of his sins, he will be granted acceptance into Heaven.