In his treatise On the Soul and the Resurrection, St. Gregory of Nyssa is said to have been taught by his sister St. Macrina regarding eschatological topics as she lay on her death-bed following the repose of their brother, St. Basil the Great. Commenting on the details of the Parable of the Rich Man and Lazarus, St. Macrina makes the following observation:
"Why, seeing that Lazarus' soul is occupied with his present blessings and turns round to look at nothing that he has left, while the rich man is still attached, with a cement as it were, even after death, to the life of feeling, which he does not divest himself of even when he has ceased to live, still keeping as he does flesh and blood in his thoughts (for in his entreaty that his kindred may be exempted from his sufferings he plainly shows that he is not freed yet from fleshly feeling)—in such details of the story (she continued) I think our Lord teaches us this; that those still living in the flesh must as much as ever they can separate and free themselves in a way from its attachments by virtuous conduct, in order that after death they may not need a second death to cleanse them from the remnants that are owing to this cement of the flesh, and, when once the bonds are loosed from around the soul, her soaring up to the Good may be swift and unimpeded, with no anguish of the body to distract her. For if any one becomes wholly and thoroughly carnal in thought, such a one, with every motion and energy of the soul absorbed in fleshly desires, is not parted from such attachments, even in the disembodied state; just as those who have lingered long in noisome places do not part with the unpleasantness contracted by that lengthened stay, even when they pass into a sweet atmosphere. So it is that, when the change is made into the impalpable Unseen, not even then will it be possible for the lovers of the flesh to avoid dragging away with them under any circumstances some fleshly foulness; and thereby their torment will be intensified, their soul having been materialized by such surroundings. I think too that this view of the matter harmonizes to a certain extent with the assertion made by some persons that around their graves shadowy phantoms of the departed are often seen. If this is really so, an inordinate attachment of that particular soul to the life in the flesh is proved to have existed, causing it to be unwilling, even when expelled from the flesh, to fly clean away and to admit the complete change of its form into the impalpable; it remains near the frame even after the dissolution of the frame, and though now outside it, hovers regretfully over the place where its material is and continues to haunt it."
Thus we see a possibility from these observations that the spirits of the dead who had fleshly or worldly attachments in this life could be so attached to their life in the flesh that their spirits remain near the bodies from which they separated. We should note that this is set down as a possible theory of why spirits seem to make their appearance near their graves.
Yet St. Gregory also warns that demons can be behind such apparitions. In his Letter Concerning the Sorceress to Bishop Theodoxios, he explains that the so-called spirit of the Prophet Samuel which appeared by the witchcraft of the Witch of Endor (1 Sam. 28) to King Saul was in fact a demon rather than his actual spirit. This view was held by other Church Fathers also, though some also proposed that this may indeed have been his spirit.
Read the entire letter here.