It comes from Tradition, although some scriptures imply it. It has not been infallibly defined by the pope or a council. I would guess it is defined as a dogma through its early and constant teaching from antiquity.
[CCC493 The Fathers of the Eastern tradition call the Mother of God “the All-Holy” (Panagia), and celebrate her as “free from any stain of sin, as though fashioned by the Holy Spirit and formed as a new creature”.138 By the grace of God Mary remained free of every personal sin her whole life long.]
[CCC508 From among the descendants of Eve, God chose the Virgin Mary to be the mother of his Son. “Full of grace”, Mary is “the most excellent fruit of redemption” (SC 103): from the first instant of her conception, she was totally preserved from the stain of original sin and she remained pure from all personal sin throughout her life.]
[CCC411 The Christian tradition sees in this passage an announcement of the “New Adam” who, because he “became obedient unto death, even death on a cross”, makes amends superabundantly for the disobedience, of Adam.305 Furthermore many Fathers and Doctors of the Church have seen the woman announced in the Protoevangelium as Mary, the mother of Christ, the “new Eve”. Mary benefited first of all and uniquely from Christ’s victory over sin: she was preserved from all stain of original sin and by a special grace of God committed no sin of any kind during her whole earthly life.306]