After the soul separates from the body at death, it enters heaven, hell, or purgatory. Whereas heaven and hell are permanent states, purgatory is a temporary state of purification for souls before entering heaven.
Some priests report that they have had success in quelling "ghostly" manifestations of spirits after counseling prayers for the final repose of such a soul or after Holy Mass is said for them.
“People report appearances of spirits—ghosts. There are a few different ways of accounting for those.”