The classic M R James story, Casting the Runes,* is a perfect example of karma coming back to bite the deserving! In it, an angry, resentful, nasty individual lives for cursing/causing the death of those he perceives to have wronged him. In the end, the victims become empowered and he gets even worse than that which he sent out into the cosmos.
People have always understood this, and thus many stories have built-in “lessons” – warnings to avoid unknown dangers of the occult, cautions to act rightly and treat others well, and to not allow feelings of shame, blame and guilt “haunt” us. Those who obsess about past perceived wrongs, problems, slights, and injustices will be eventually consumed by them. Healing (whether counseling, spiritual, or even (in extreme cases), exorcism) is essential to move on in an integrated way. Looking at this from another angle: we may be haunted by our own feelings – we ourselves may be the haunters as well as the hauntees.
Then there’s the person who scorns or belittles the dangers of hauntings and ghosts: these people often become the focus of paranormal events! This is true in fiction and has happened in real life. I recently saw a telecast about an individual, a private investigator, who absolutely didn’t believe in ghosts. He was hired to debunk a certain case, which ended up making a believer of him. Now his focus is working with those struggling with haunting.
A fictional example is the character Inglis in the E F Benson story, Caterpillars.* At the outset, Inglis makes a point of declaring that those who believe in ghosts are fools, there’s no such thing. Unfortunately for him, the setting of the story is a haunted one. He ends up, after dissing an aspect of the phenomena, becoming victimized by it. But the reader is left with “Well, he did ask for it.” Rather like the little boy whose mother says “don’t touch the hot stove!” but he does anyway. (Sometimes it just takes life experience to build a learning curve)!
While karma isn’t a factor in all hauntings (fiction or true accounts) it often plays a significant role, and can be seen as a common “moral of the story” in ghostly tales of all kinds.
https://www.amazon.com/Jan-Olandese/e/B071FK9L75
*(Both Casting the Runes by M R James and Caterpillars, by E F Benson, are free to read online – see google to access links).