I mean, the origin of the Mourners’ Kaddish, according to one medieval midrash, was to get rid of a ghost/undead spirit (see here and here):
A tale of R. Akiva. He was walking in a cemetery by the side of the road and encountered there a naked man, black as coal, carrying a large burden of wood on his head. He seemed to be alive, and was running under the load like a horse. R. Akiva ordered him to stop.“How comes it that a man does such hard work?” he asked. “If you are a servant and your master is doing this to you, then I will redeem you from him. If you are poor and people are avoiding you, then I will give you money.”“Please sir,” the man replied. “Do not detain me, because my superiors will be angry.”“Who are you,” Rabbi Akiva asked, “and what have you done?”
The man said, “The man whom you are addressing is a dead man. Every day they send me out to chop wood.”“My son, what was your work in the world from which you came?” “I was a tax collector, and would favour the rich and kill the poor.” “Have your superiors told you nothing about how you might relieve your condition?” “Please sir, do not detain me, for you will irritate my tormentors. For such a man [as I], there can be no relief. Though I did hear them say something—but no, it is impossible. They said that if this poor man had a son, and his son were to stand before the congregation and recite the prayer Barekhu and the congregation were to answer amen, and the son were also to say Yehe shme mevarakh, they would release him from his punishment. But this man never had a son. He left his wife pregnant and he did not know whether the child was a boy. And if she gave birth to a boy, who would teach the boy Torah? For this man does not have a friend in the world.” Immediately Rabbi Akiva took upon himself the task of discovering whether this man had fathered a son, so that he might teach the son Torah and install him at the head of the congregation to lead the prayers. “What is your name?” he asked. “Akiva,” the man answered. “And the name of your wife?” “Shoshnia.” “And the name of your town?” “Lodkiya.”
Rabbi Akiva was deeply troubled by all this and went to make his inquiries. When he came to that town, he asked about the man he had met, and the townspeople replied, “May his bones be ground to dust!” He asked about the man’s wife, and he was told, “May her memory be erased from the world!” He asked about the man’s son, and he was told, “He is a heathen—we did not even bother to circumcise him.” Rabbi Akiva promptly circumcised him and sat him down before a book. But the boy refused to receive Torah. Rabbi Akiva fasted for forty days. A heavenly voice was heard to say, “For this you mortify yourself?” “But Lord of the Universe,” Rabbi Akiva replied, “It is for You that I am preparing him.”
Suddenly the Holy Blessed One opened the boy’s heart. Rabbi Akiva taught him Torah, the Shema, and Birkat haMazon. He presented the boy to the congregation and the boy recited Barekhu and they answered Barukh hamevorakh le’olam va’ed. At that very moment the man was released from his punishment. The man immediately came to Rabbi Akiva in a dream and said, “May it be the will of the Lord that your soul find delight in the Garden of Eden, for you have saved me from the sentence of Gehenna.” … For this reason, it became customary that Ma‘ariv on the night after Shabbat is led by a man who does not have a father or a mother, so that he can say Kaddish and Barekhu.