I kinda have a theory... Hear me out
My little dumb theory about ghosts is that when you die you have two options, continue you journey beyond the mortal plane wich is tailored by your religion or the thing you believe the most OR continue being here, so you can "finish your pending stuff"
Idk, it seems probable to me, there's has been cases of murder that haven't left "haunted" the place, but other ones surely afirm that some places got haunted after something awful happened... why sometimes happens and sometimes don't?
Also in my little theory exists the fact that ghosts are not in the mortal world, they are in other place, and only the stronger ones are able of doing something that reflects over here. Something like the movie interstellar, were you couldn't move in space but you could in time and the actions of the protagonist were represented as a ghost in the start of the movie. Or maybe they're actually here with us, but they just can't interact, or they require to do a huge effort that could make them feel weak or ill for doing such a thing
But hey, that's just a theory... A Ghostly Theory!