St. Thomas Aquinas did not have a chance to fully develop his thoughts about spirits and apparitions, but we were left a glimpse of his thoughts on the matter. The section is found in the Summa Theologica, Supplementum Tertiæ Partis: Question 69. Matters concerning the resurrection, and first of the place where souls are after death, Article 3. Whether the souls who are in heaven or hell are able to go from there?
St. Thomas knows his answer will be pushing a bit against Augustine, so he addresses Augustine’s argument about Monica in his first Objection/Reply:
Augustine, as may be gathered from what he says afterwards, is speaking according to the common course of nature. And yet it does not follow, although the dead be able to appear to the living as they will, that they appear as often as when living in the flesh: because when they are separated from the flesh, they are either wholly conformed to the divine will, so that they may do nothing but what they see to be agreeable with the Divine disposition, or else they are so overwhelmed by their punishments that their grief for their unhappiness surpasses their desire to appear to others.
This does not address the Augustinian argument in its fullness. (This section of the Summa was compiled from other writings, after his death, by Fra Rainaldo da Piperno, and therefore its weaknesses should not be attributed to Thomas.) Augustine isn’t talking about frequency of apparitions, but about the mere possibility of them. Augustine freely admits that God may allow his angels or saints to appear in the world for His Own purposes, but his argument is more subtle and complex, and he seems to allow this possibility somewhat begrudgingly and anecdotally.
Thomas, on the other hand, is reflecting a more developed medieval sense of ghosts who may indeed have an active role in the world, as permitted by God for the His glory or the betterment of man.
There are some weaknesses in Thomas’s argument. He makes his case that only the saints and damned may be seen upon the earth without appearing much concerned by the main question that vexed Augustine: how are they seen, with what vision, and what kind of bodies are seen if the soul is immaterial?
Thomas accepts, with Augustine, that some ghosts aren’t seen with corporeal vision, but declines to develop the idea:
Thus sometimes even the living appear to others and tell them many things in their sleep; and yet it is clear that they are not present, as Augustine proves from many instances.
Thomas also makes recourse to St. Gregory the Great’s Dialogues in his argument, but fails note that the most famous ghost story in that book is of neither saint nor damned, but merely a restless spirit looking for release.
Curiously, he relies upon St. Jerome rather than Augustine for his sed contra, quoting Jerome against Vigilantius:
For thou sayest that the souls of the apostles and martyrs have taken up their abode either in Abraham's bosom or in the place of refreshment, or under the altar of God, and that they are unable to visit their graves when they will. Wouldst thou then lay down the law for God? Wouldst thou put the apostles in chains, imprison them until the day of judgment, and forbid them to be with their lord, them of whom it is written: They follow the Lamb whithersoever He goeth? And if the Lamb is everywhere, therefore we must believe that those also who are with Him are everywhere.
…
Since the devil and the demons wander throughout the whole world, and are everywhere present with wondrous speed, why should the martyrs, after shedding their blood be imprisoned and unable to go forth?
Thomas adds firmly: “Therefore it is absurd to say that the souls of the departed do not leave their abode.”
Again, this is further than Augustine is willing to go, but reflects the more developed medieval attitudes, which allowed a place for ghosts. This paralleled the more advanced considerations of purgatory in the middle ages, and allowed for souls in purgatory to visit the living through a semi-permeable membrane between living and dead.
It's not that purgatory was "invented" in the middle ages. (Even Jacques le Goff admits the belief is found in the Early Church.) It's that beginning in the 12th century, we have a more elaborate theology and visionary experience of purgatory which leads it to a more central place in the life of the church. With this, we see an expansion of the ghostly literature as it becomes a kind of adjunct to the literature of purgatory.
If we are to believe the Vita of Thomas by his fellow Dominican Bernard Gui (and there's no reason not to), Thomas himself had ghostly encounters. One was with his sister, requesting prayers for her soul in purgatory, and then again when she had been freed from purgatory. The other was with Brother Romanus, who visited Thomas to announce his own death, sojourn in purgatory, and subsequent passage to eternal life.
There’s some discomfort in this, because while many ecclesial writers eject great clouds of qualifications about ghosts only being able to do the will of God, the literature reflects a more messy reality of saints, demons, and ordinary folk. The restless spirit in purgatory was already becoming a staple around the time of Thomas, and these tales, though often given a Christianizing veneer, often had deeper roots in ghostly, often pagan, folklore.
By the time of Thomas, much of Augustine’s nuance and qualification was, for all practical purposes, discarded. The unquiet dead were a social reality and weren’t going to be banished by pure theology, so they were gradually folded into the life of the church, albeit on the margins and never “officially."
In all my reading on the subject (and although I don’t pretend it’s anything close to comprehensive, it’s pretty extensive) I have not yet come across an official magisterial statement on ghosts. The Church, of course, allows great latitude for the actions of saints doing the will of God, but as for the power of the ordinary unquiet dead—neither blessed nor damned—to visit the living, she appears to remain silent. If someone is aware of something I’ve missed on that front, I’d love to hear about it.
To conclude, here is the full article by Thomas:
There are two ways of understanding a person to leave hell or heaven.
First, that he goes from thence simply, so that heaven or hell be no longer his place: and in this way no one who is finally consigned to hell or heaven can go from thence, as we shall state further on (71, 5, ad 5).
Secondly, they may be understood to go forth for a time: and here we must distinguish what befits them according to the order of nature, and what according to the order of Divine providence; for as Augustine says (De Cura pro Mort. xvi): "Human affairs have their limits other than have the wonders of the Divine power, nature's works differ from those which are done miraculously."
Consequently, according to the natural course, the separated souls consigned to their respective abodes are utterly cut off from communication with the living. For according to the course of nature men living in mortal bodies are not immediately united to separate substances, since their entire knowledge arises from the senses: nor would it be fitting for them to leave their abode for any purpose other than to take part in the affairs of the living.
Nevertheless, according to the disposition of Divine providence separated souls sometimes come forth from their abode and appear to men, as Augustine, in the book quoted above, relates of the martyr Felix who appeared visibly to the people of Nola when they were besieged by the barbarians.
It is also credible that this may occur sometimes to the damned, and that for man's instruction and intimidation they be permitted to appear to the living; or again in order to seek our suffrages, as to those who are detained in purgatory, as evidenced by many instances related in the fourth book of the Dialogues.
There is, however, this difference between the saints and the damned, that the saints can appear when they will to the living, but not the damned; for even as the saints while living in the flesh are able by the gifts of gratuitous grace to heal and work wonders, which can only be done miraculously by the Divine power, and cannot be done by those who lack this gift, so it is not unfitting for the souls of the saints to be endowed with a power in virtue of their glory, so that they are able to appear wondrously to the living, when they will: while others are unable to do so unless they be sometimes permitted.