Belief in ghosts and the afterlife was common in Shakespeare's time, the variance in views and opinions were rooted in religion.
Catholics believed in the doctrine of purgatory and that ghosts were the spirits of those returning for some special purpose. These spirits should be aided if possible so that their soul may find rest. The Ghost told Hamlet he is doomed to walk the night "till the foul crimes done in my days of nature are burnt and purg'd away." (1.5.12-13) The Protestants however denied the doctrine of purgatory and believed that a person's soul went directly to either heaven or hell. Ghosts were usually regarded as demons, which sought the downfall of their victims, and should be resisted. (Carlson & Peel, 2003, p. 9) Horatio had similar concerns after initial sight of the Ghost, "this bodes some strange eruption to our state." (1.1.72) Another belief was that ghosts could be hallucinations, "an illusion of melancholic minds or flat knavery on the part of some rogue."
(Wilson, 1976, p. 63) This theory is quickly refuted in the first Act as it is unlikely that Barnardo, Marcellus, Horatio and Hamlet had all seen a hallucination.
There is no mention of purgatory or praying for the dead within the play. Although the Ghost of Hamlet's father has died without the last rites being observed, he never asks for prayers for the repose of his soul. "Like some hellish demon, he appears only at night and vanishes before sunrise, demanding only revenge." (McConnell, 2000, p. 107-108) Shakespeare left the state of religion in Denmark ambiguous.
Hamlet accepted the ghost as a spirit, and never shows the slightest sign of hesitation in this belief. What he doubts is the identity of the Ghost and the nature of the place from which it came.