The crux of Stephen Greenblatt's book Hamlet in Purgatory is that William Shakespeare used the Ghost in Hamlet to represent the Catholic concept of Purgatory.
The Medieval Church (the Catholic Church) was quite interested in the concept of a place called Purgatory, a rather nebulous stopping place between death and either heaven or hell. Purgatory is both a beautiful and an awful place, claimed the Church. It was located in Donegal, Ireland, but it was also a place of horrific and rather fantastical tortures which those who have died must endure for as long as two thousand years before finally moving on to their final destinies.
Fortunately for those who were left behind and worrying endlessly about their loved ones, the Church had an answer: what the living relatives and friends must do is pray, do charitable acts, and of course donate money to the church on their loved ones' behalf. Greenblatt does make it clear that the priests were not the only ones whose prayers were considered to be effective in this endeavor; however, he is also clear that most of the building and other projects done by the Medieval Church were funded by these fear-inspired donations to the Church.
Despite the rather materialistic motives of the Church as they exploited and perpetuated the idea of Purgatory, the people did derive some comfort from the thought that they could do something to alleviate their loved ones' pain and suffering.
Now on to Shakespeare and Hamlet. By the time Shakespeare is writing, says Greenblatt, the teachings of the Catholic Church have been superseded by the Protestant Church after the Reformation, and because the Church of England does not accept the concept of Purgatory, the people are forced to think differently about the afterlife. This void is filled, he says, by ghosts, spirits, and apparitions from another place, so often present on the Elizabethan stage. In other words, the theatre could give the people what the Church could not.
Enter Hamlet's Ghost. He talks to his son about the place where he is trapped:
I am thy father’s spirit,Doomed for a certain term to walk the nightAnd for the day confined to fast in fires,Till the foul crimes done in my days of natureAre burnt and purged away. But that I am forbidTo tell the secrets of my prison house,I could a tale unfold whose lightest wordWould harrow up thy soul, freeze thy young blood,Make thy two eyes, like stars, start from their spheres,Thy knotted and combinèd locks to partAnd each particular hair to stand on end,Like quills upon the fearful porpentine.But this eternal blazon must not beTo ears of flesh and blood.