The tradition is based on a verse from the Book of Genesis, in which the downfall of Satan is predicted.
One of the most common depictions of the Virgin Mary has her standing on a snake. Why is that?
The tradition finds its roots in a biblical verse that was translated in the Latin Vulgate (which was later translated into English in the Douay-Rheims Bible). In the Book of Genesis, shortly after Adam and Eve ate the forbidden fruit in the garden, God curses the serpent who tricked them and foretells his ultimate destruction.
I will put enmities between thee and the woman, and thy seed and her seed: she shall crush thy head, and thou shalt lie in wait for her heel. (Genesis 3:15)
Initially this was taken by the Church to refer to Mary, the woman who would give birth to the Messiah. It would be through her “Yes,” that Satan would be defeated and the curse of Eve lifted.
St. Irenaeus puts it eloquently, “[Jesus’] obedience on the tree of the cross reversed the disobedience at the tree in Eden; the good news of the truth announced by an angel to Mary, a virgin subject to a husband, undid the evil lie that seduced Eve, a virgin espoused to a husband. As Eve was seduced by the word of an angel and so fled from God after disobeying his word, Mary in her turn was given the good news by the word of an angel, and bore God in obedience to his word.”