We can deduce the answer to this from the Ghost's speech to Hamlet in Act 1, Scene 5. The ghost tells Hamlet that he is "doomed" to walk around at night and that he spends his days being burned in fires. This may sound to a modern audience as if he is saying he is in hell, but the ghost specifically tells Hamlet that he is only bound to do this until he has been "purged" of all the crimes he committed while he was alive, the fires having the cleansing power to burn his sins away. This description would be recognized by Shakespeare's audience not as one of hell, but instead as a description of purgatory.
Purgatory was understood to be a realm in which the soul waits after death until such time as it is pure enough to move on to a better realm. The idea of purgatory supposedly emerged in the twelfth century. Notably, it was believed that the prayers of the living could help a soul move on from purgatory, which explains why the ghost appeals to Hamlet in this section. The belief was that Hamlet could still help his father in some way.