The question really ought to be why are 5 women mentioned, since Mary is mentioned last as the mother of Jesus.
Some commentators note a numerical coded pattern of 7 (the numeric representation of perfection) or multiples that suggests that this may be some sort of coded message with a hidden meaning that has long been lost.
The author has deliberately added these five women and evidently left out some male generations (possibly because they destroyed the sequence of 14 (double perfection) generations). The Imperfect actions of these women aiding the double perfect plan. King David, the name in numerics is D-V-D is represented as D = 4, V = 6, D = 4, which equals 14 - double perfection. It is 14 generations from Abraham to King David (Double perfect ruler of Israel), 14 generations from David to the greatest calamity of the exile, and 14 generations from the exile to the saviour. Yet Matthew added these 5 women who's imperfect actions aided the double perfect plan of God's salvation for all .
It cannot be a lineal genealogy of Jesus since if we take it at face value, then if Jesus is fathered by the Holy spirit, the lineage mentioned is null and void, since hereditary descent is always through the male line, not the female line. These 5 women were all involved in some scandalous sexual impropriety, 4 were foreigners (non-Jew, gentiles) which at first glance, destroys any claims that Jesus had a 'pure' national blood line. Note Also Mary is mentioned as the mother of Jesus, and is herself involved in the scandal of pregnancy outside of wedlock. And yet all 5 women played vital roles in furthering the advancement of the kingdom of God in their time. In other words, God used the activities of scandalous women to aid the Israelites and further God's plan.
Rahab was a prostitute in Jericho who aided the Israelite spies and directly furthered God's plan.
Ruth was the grandmother of king David.
The wife of Uriah the Hittite, had an adulterous relationship with David, and fathered Solomon the wisest ruler of Israel - So God used an adulterous relationship to create the greatest king of the Jews.
Mary was the mother of Jesus the saviour.
If the whole genealogy in Matthew is meant to represent God's doubly perfect plan then by including these 'fallen' women, the author is saying that God's plan for salvation can mitigate even the gravest of sins, and use the greatest of Sinners for his cause. It also shows that God had always planned for salvation to include even the lowest of outcasts from Israelite/Jewish society, by using foreign women to represent gentiles.
There may well be some secret numerology embedded within the text, then could these women have been added because the numerology of their name adds some kind of code revolving around the number 7 that typically represents perfection?