Interestingly enough, I’ve been working through this issue for a paper at seminary. Dr. Peter Kreeft mentions the possibility of ghosts in his “Angels (and Demons)” book listing a few reasons for the possibility: 1) they don’t realize they are dead 2) they were so attached to something on earth they can’t detach themselves from it 3) they are working out some form of purgatory or purification 4) they are consoling their loved ones who have been bereaved. The Anglican Exeter report (official report on Exorcism) also mentioned “place memories” and souls of the departed as possible reasons besides demonic for “haunts”. Justin Martyr held that the souls of the Nephilim became demons, and in that sense held to “ghosts” (cf. 2 Apo. Ch5) See also “The Unseen World” ed. Anthony Lane, Pater Noster Press for an article on demons and ghosts (I don’t agree with it completely, but it is interesting)
On the other hand if you can pick up “A Treatise of Ghosts” by Father Noel Taillepied (1540-1589) translated by the famous (?) Montague Summers, he argues departed souls to return but only to bring specific messages and not to “haunt” places. Which is somewhat consistent with Tertullian who testifies that at times demons would pretend to be some dead spirit, but when Christians cast them out they were made to tell the truth and confessed to being demonic. (cf. Treatise on the soul Ch57)
Scripture seems somewhat ambiguous, although would imply that “haunting” by actual spirits of the dead may be very rare, and that demons certainly can trick people into thinking they are some dead family member or other. One Anglican book that tries to answer the question from a pastoral perspective is “Healing Death’s Wounds” by Michael Mitton and Russ Parker. Ultimately an Exorcist should be called in to assess the situation because if it is not a ghost it may be demonic. (Mitton and Parker suggest a Requiem Eucharist/Mass in case of dead spirits)
That is some of what I know so far, which I could help you one more of the Catholic sources, but there does not seem to be a definite position within Scripture or Tradition.