Thomas built a theory of sanctification that assumed an underlying scientific understanding of conception and ensoulment that happened to be in error, but was common throughout all the centuries preceding his own.
No one knew that women produced eggs, and this knowledge would not, in fact, be confirmed until the early 1800s. Since all things are created in, by and for Christ, the operations of the natural world are properly a subject of theology. Further, since God took flesh and walked in the natural world, the operations of the natural world are also part of the necessary foundation to Christian theology.
Unfortunately for Thomas, none of the Christian theologians had a detailed or complete understanding of how conception worked. Thomas assumed that conception happened first, and the rational soul was infused at some later point. This was an error. Despite this error he pointed out an incontrovertible fact:
"The sanctification of the Blessed Virgin cannot be understood as having taken place before animation, for two reasons. First, because the sanctification of which we are speaking, is nothing but the cleansing from original sin: for sanctification is a "perfect cleansing," as Dionysius says (Div. Nom. xii). Now sin cannot be taken away except by grace, the subject of which is the rational creature alone. Therefore before the infusion of the rational soul, the Blessed Virgin was not sanctified.
Secondly, because, since the rational creature alone can be the subject of sin; before the infusion of the rational soul, the offspring conceived is not liable to sin. And thus, in whatever manner the Blessed Virgin would have been sanctified before animation, she could never have incurred the stain of original sin..." (emphasis added)All he said was, the Blessed Virgin HAD to have been saved from original sin or Christ would not be universal saviour - a perfectly correct statement:
"If the soul of the Blessed Virgin had never incurred the stain of original sin, this would be derogatory to the dignity of Christ, by reason of His being the universal Saviour of all. Consequently after Christ, who, as the universal Saviour of all, needed not to be saved, the purity of the Blessed Virgin holds the highest place."And he even admitted that celebrating the Feast of the Immaculate Conception was not a problem:
"Although the Church of Rome does not celebrate the Conception of the Blessed Virgin, yet it tolerates the custom of certain churches that do keep that feast, wherefore this is not to be entirely reprobated. Nevertheless the celebration of this feast does not give us to understand that she was holy in her conception. But since it is not known when she was sanctified, the feast of her Sanctification, rather than the feast of her Conception, is kept on the day of her conception." (emphasis added)So, he essentially admits that if his understanding of how ensoulment works is wrong, then the Immaculate Conception was properly a feast. He even admitted that his theory could be wrong when he agreed that the Feast of the Immaculate Conception could be licitly celebrated, since no one knew exactly when she had been sanctified. The reason no one knew was because no one knew exactly when the rational soul was infused.
He did not deny the Immaculate Conception, he only denied that Mary could have been sanctified before the infusion of her rational soul - a perfectly reasonable theological position. We don't baptize dogs because dogs don't have rational souls. We don't sacramentally anoint chairs or tables because they don't have souls at all.
If Thomas had known the infusion of the rational soul took place at conception - which is what the dogma of the Immaculate Conception implies - he would have instantly agreed that the Immaculate Conception was a reasonable teaching: