Matthew’s genealogy forms the preface to an extended account of Jesus’ nativity in which Mary plays the most prominent role.
But Matthew’s genealogy cannot be taken “literally.” It has been edited to make a “theological” point, as virtually everyone has recognized since antiquity. But what point?
Although not literally Mary’s genealogy, I believe that Matthew included these women of “ill repute” as a polemic. Mary fits into the genealogy in the same way Tamar, Rahab, and Bathsheba do. Women whose virtue was questioned, to say the least, but who played an otherwise critical (indispensable) role in the perpetuation of the lineage.
As “Gone Quiet” wrote, these women “redeemed” themselves in the Scriptures—a fact that men (who record the genealogies) may overlook. After all, men expect women to be more virtuous, and may be less forgiving when they are not—especially when the infraction committed by women is sexual. (And nevermind that every man in these genealogies is a sinner.)
Well aware of the fact that God is no respecter of persons Matthew's genealogy is scandalous.
This may even serve to date Matthew’s Gospel—it was, at least in its introduction, written to counter the charge that Jesus was “illegitimate.” A charge made early in Jesus’ ministry (See John.) If Jesus was "illegitimate" so were so many men included in the genealogies of honored men.
Such a charge (illegitimacy) would have had little effect outside an exclusively Jewish milieu. And would have been rendered moot after the more-or-less systematic destruction of Jewish records by Herod, the Zealots, and the Romans in the first century.
It's really Mary's genealogy, not even Jesus', spiritually, not literally.