Objection 1: It seems that it was inappropriate for the Mother of God to go to the temple to be purified. For purification presupposes impurity. But in the most blessed Virgin there was no impurity, as stated above (Questions [27], 28). Therefore, she should not have gone to the temple to be purified.
Objection 2: Furthermore, it is written (Lev 12:2-4): “If a woman has conceived seed and borne a male child, she shall be unclean for seven days”; and consequently, she is forbidden to enter the sanctuary until the days of her purification are completed. But the most blessed Virgin bore a male child without receiving the seed of a man. Therefore, she had no need to come to the temple to be purified.
Objection 3: Furthermore, purification from impurity is effected solely by grace. But the sacraments of the Old Law did not confer grace; moreover, she had with her the very Author of grace. Therefore, it was not fitting that the most blessed Virgin should come to the temple to be purified.
On the contrary is the authority of Scripture, where it is said (Lk 2:22) that “the days” of Mary’s purification “according to the law of Moses were fulfilled.”
I answer that: Since the fullness of grace overflowed from Christ onto his mother, it was fitting that the mother should be like her Son in humility: for “God gives grace to the humble,” as it is written in James 4:6. And therefore, just as Christ, although he was not subject to the Law, nevertheless wished to submit himself to circumcision and the other burdens of the Law, to give an example of humility and obedience; and to show his approval of the Law; and again, to deprive the Jews of an excuse for slandering him: for the same reasons, it was fitting that his mother also fulfill the prescriptions of the Law, to which she was nevertheless not subject.
Reply to Objection 1: Although the most blessed Virgin had no impurity, she nevertheless wished to observe the purification, not because she needed it, but because of the prescription of the Law. Thus, the Evangelist expressly says that the days of her purification “were fulfilled according to the Law”; for she had no need of purification in herself.
Reply to Objection 2: Moses seems to have chosen his words so as to exclude impurity from the Mother of God, who “conceived without receiving seed.” It is therefore clear that she was not obliged to fulfill that prescription, but observed the purification of her own accord, as stated above.
Reply to Objection 3: The sacraments of the Law did not cleanse from the impurity of sin, which is done by grace, but foreshadowed this cleansing: for they purified by a kind of carnal purification from the impurity of a certain irregularity, as set forth in the FS, Question [102], Article [5]; FS, Question [103], Article [2]. But the most blessed Virgin incurred no impurity and therefore did not need purification.
Source: Summa Theologiae, Third Part, Question 37, Article 4