Mary went through the post-childbirth purification ceremony for the same reason Jesus went through the post-childbirth circumcision ceremony: out of obedience to the Mosaic law. Both rites—purification (ritual cleansing of the mother) and circumcision (removing the foreskin of the child)—symbolized being freed from sin. Jesus and Mary underwent them not because they needed to be freed from sin but because they were Jews who followed the Mosaic law. That’s why Jesus was baptized: not because he needed it himself but to set the pattern for us to follow.
St. Thomas Aquinas explains Mary’s purification ceremony in this way:
As the fullness of grace flowed from Christ on to his Mother, so it was becoming that the Mother should be like her Son in humility: for "God giveth grace to the humble," as is written James 4:6. (Summa Theologiae III:37:4)