A number of years ago I worked as a carpenter in a theater. As all theaters are rumored this one sported tales of its very own ghost who banged around in the catwalks at night scaring the night security guards. We were running way behind schedule and I found myself working late into the night, falling asleep in the theater several nights in a row. Sure enough I heard the banging. It was loud enough to wake me out of a very sound sleep. Was it a ghost?Saint Thomas Aquinas tells us that at death the soul is separated from the body like a ball full of air that has been pushed underwater and then let go. Immediately the soul either soars to heaven or plunges into hell. So does that discount the possibility of ghosts according to Church teaching?
Not exactly. Most people, I think, would be shocked at how much the Church has not made a definitive statement on and ghosts are one of those things. There are allowances for the possibility of them. Some of those possibilities involve purgatory. Some souls are going to heaven but have not yet been completely cleansed of their earthly attachments and so must go through a purgation as nothing unclean will enter before the presence of God. We only have a sketchy and somewhat symbolic idea of what purgatory is. Is there a possibility that a soul might have some dealings with earthly things as part of its purgation? Maybe.
There may also be the case too that God might allow us to see either in dream or vision a person deceased in order to remind us to pray for them or to call us to holiness. Samuel prophesied from the grave and we readily accept for the possibility of saint speaking to us such as at Fatima.

Of course we also know that angels as a cosmic force act in the world. We have only to look at the Annunciation for that. But if good angels can act, so can evil ones. We see this in the demons that Christ regularly banished from people.
I am highly skeptical about such activity but still find it something not to mess around with. Every diocese has an exorcist and they aint around for kicks (though they are very seldom called upon). But the other world is like electricity. Properly experienced there is absolutely nothing dangerous or wrong with it. Improperly used it can kill you.
Are we forbidden contact with the next world? No! We do it all the time. But we do it as God bids us. It is called prayer and intercession. Even legitimate scientific study is not completely outlawed “provided there is no recourse to means that are essentially immoral or specifically forbidden.”
But trying to control cosmic forces, using spirits to gain knowledge from God’s realm, (a form of divination) evocation of the dead, these are all forbidden actions. Such actions lead to superstition, possibilities of being frauded, and the very real chance that one is dealing with a decepting spirit.
If you feel you are being visited by a “ghost”, I would probably think there was more likely a more earthly explanation. But if not, if it is of God there is nothing to fear. Pray. If it is not of God, you have nothing to fear for you always have God. Pray.
Though I tend not to believe in such things, tired of being kept up late at night in that theater I climbed up into the catwalks and said a prayer for the soul of our “ghost”. The banging stopped. From then on. That means I either prayed a cure for the hot water pipes, or perhaps a soul went to his reward. Who knows?