The Bible seems to take the existence of ghosts for granted. It reports and mentions them, and commands us not to have recourse to them, but it never says they don't exist or that they are always demons. The most famous example, of course, is the ghost of Samuel that is conjured up by the witch of Endor at the command of Saul and God permits it. Isaiah matter-of-factly mentions ghosts in Isaiah 19:3 and 29:4. When Jesus comes walking across the waves in Matthew 14:26, the disciples cry out that "It is a ghost!" and neither Jesus or Matthew offer a corrective saying there is no such thing. Jesus himself refers to the properties of ghosts when he appears to the disciples on the evening of Easter in Luke 24:37-39. They think he is a ghost, but he reassures them by reminding them of the qualities that ghosts possess. He doesn't dismiss their belief in ghosts or even qualify it by saying something like, "as you imagine a supposed ghost might have," but, again, uses the term matter-of-factly.
True appearances of ghosts do not seem to be common, and they are definitely out of the normal or natural order of things. But as in the example of Samuel, God in his singular Sovereignty and Omnipotence for his own Omniscient reasons, can and apparently does, make exceptions for his own purposes. But careful discernment is necessary on our part to differentiate between the apparition of a human soul (ghosts) or deceitful and malevolent demonic activity.
Samuel was a very special instance. The other mentions of ghosts were by citizens, who had their cultural superstitions, but it doesn’t, mean they are real. As mentioned, when the soul departs the body, it either awaits hell, and “knows nothing” until that time, or is immediately in heaven. Can God cause a spirit to visit someone? Sure, he his able to do supernatural things like that, but I suspect it is very very rare, a d for very specific purposes. A humber of “ghost hunters’ note that they became possessed, or “haunted” as they call it, and that is indicative of demon possessikn/attacks, souls that depart would not have suoernatural power like that almost assuredly.
Abraham said: βAnd besides all this, between us and you a great chasm has been fixed, so that those who want to go from here to you cannot, nor can anyone cross over from there to us.β
Demons are not bound by such restraints however.