I really think Matthew puts as much effort into preparing his readers to understand Mary as Luke does. Luke is famously Mary-centered. In Luke, Joseph is part of the ensemble, back there with the oxen and the asses. He doesn’t speak a single line. But in Matthew, Joseph is in David’s line of descent and that is why his son is “a child of David.”
Although Matthew does not feature Mary—Mary does not have a spoken line in Matthew’s account—Matthew needs to prepare his readers to understand who she is and what she has done for us. Of all the ways he does that, I want to think today about the genealogy he presents. This is a royal genealogy. The king’s son is king after him; the grandson is king after the son; the great-grandson king after the grandson. We don’t really need to know who the mother is if the father is the king.
And mostly, Matthew does not tell us who the mother is. Matthew’s genealogy is arranged in sets of fourteen, so to make this point, we can look at the the first fourteen, beginning with Abraham and ending with David the King. “Abraham fathered Isaac, Isaac fathered Jacob, Jacob fathered Judah and his brothers.” That’s the way it goes (Matthew 1:2) and that is the way we expect it to go. But if it continued that way, how would Matthew be preparing us for a pregnant virgin? (The picture comes from Luke. Sorry. It was the only way to have a picture.)
So we begin to see breaks in the pattern. He ended with “Judah and his brothers,” the sons of Jacob. But now Matthew says, (verse 3) “Judah fathered Perez and Zerah, whose mother was Tamar.”
The mother was Tamar? Why? Matthew didn’t bother to tell us that Isaac’s mother was Sarah, nor that Jacob’s mother was Rebecca, nor that Judah’s mother was Leah. Why break the pattern to tell us about Tamar? Hold that thought.
A few generations later, we find another break. Verse 5 tells us that Salmon fathered Boaz, whose mother was Rahab; and right after that, Boaz fathered Obed, whose mother was Ruth. Then, in the second part of verse 6, that “David fathered Solomon, whose mother had been Uriah’s wife.”
So we have a clear pattern. We have not yet addressed how these breaks help Matthew prepare us for the role Mary plays. Matthew drops in the mother in addition to the father four times. And then we get to Mary. “Jacob fathered Joseph, the husband of Mary, of her was born Jesus who is called the Christ.” (verse 16)  In the case of Mary, a new pattern is substituted because Matthew does not want to say that Joseph fathered Jesus. That phrasing sounds like sperm and egg stuff and that’s not what Matthew wants to say.  The picture shows Tamar seducing Judah.
So these four breaks in the pattern—Tamar, Rahab, Ruth, and Bathsheba—are introduced to help prepare us for Mary in some way. How do they do that? We could stop and note that they were foreigners; all but Bathsheba, who is not called by her name, but “the wife of Uriah the Hittite.” That might be part of it.
The role each woman plays is morally ambiguous. Matthew is going to record some accusations against Jesus in 11:19. “Look,” his accusers say, “a glutton and a drunkard, a friend of tax collectors and sinners.” Matthew doesn’t allow any of Jesus’s accusers to point a finger at Mary and shrug and say, “Like mother, like son.” I do think that Mary’s morally ambiguous situation has been prepared for by the women who preceded her—the women Matthew had to break his pattern to introduce. Let’s look at the cases Matthew gives us.
Tamar, after all, had extramarital sex with her father-in-law, Judah. Rahab was a traitor to her people, the Canaanites, by harboring Israelite spies. Ruth put herself in a very compromising on the threshing room floor with Boaz. Bathsheba was taken, probably against her will, by the king, who then killed her husband, Uriah the Hittite. These women lead us to Mary…how exactly?
I can think of two ways.  I don’t know whether these are the ways Matthew had in mind. The first is that these women aligned themselves with the story God was telling through them. Tamar, for instance, was fixed on the notion that descendants were to be raised up in the name of her dead husband, Er. That’s what God said should be done and she couldn’t find anyone else who was interested in doing what God said should be done. She counted on an array of men to do the job (including her brother-in-law, Onan, Onan’s younger brother Shelah, and Judah, the patriarch, which is where the buck stopped. When they would not, she did it herself. She disguised herself as a prostitute and got herself pregnant by Judah, her father-in-law. And the children were reckoned to be the children of her husband, Er. 
God says, in other words, that children shall be raised up to carry on the line of the dead husband. That’s what God says. Everyone said no except Tamar. She “aligned herself with the story God was telling” by getting pregnant out of wedlock.
Rahab, the traitor, threw her lot in with the invading Israelites and against her people, the Canaanites. Since the only account we have of that comes from the Israelites, Rahab is revered. And without Rahab, there would have been no inhabitation of the Promised Land by God’s people—at least not in the way it actually happened. And without the Promised Land, of what nation would David have been king? It is all very well to say, as Matthew does, that Ruth’s husband Boaz fathered Obed, who was the father of Jesse, who was the father of David, but if there is no kingdom, there is no king and it was Rahab the traitor who aligned herself with God’s story in helping establish a kingdom. The picture shows Ruth on the threshing room floor with Boaz; actually, it shows more of her than scripture really requires.
That brings us, skipping over the fascinating story of Ruth, to Mary herself. You know, the “pregnant out of wedlock” Mary? The initiative-taking Mary? The aligning herself with God’s story Mary?
By the time we get to Mary, the Mary for which Matthew has prepared us, we know that “racial purity” is not going to be any part of Jesus’s claim to be Messiah. Paul can call himself “a Pharisee of the Pharisees,” but he does not call Jesus that. Jesus was born on the other side of the track in socially embarrassing circumstances and he was born to a woman who aligned herself with God’s story—like her predecessors, Tamar, Rahab, Ruth, and Bathsheba.
 Nor that he had fathered another son, Ishmael, before Isaac.
 Joseph, by taking and naming the child, declares himself to be the child’s father according to Jewish law. Joseph was his father “fully and legally,” to use and expression biblical scholar Raymond E. Brown uses. And Mary calls Joseph the father of Jesus as well (Luke 2:48). The question in these cases is not genetic, but legal.
 Actually, Matthew wants to talk about “a new creation,” but that will have to wait for another essay.
 At some point in this essay, I need to acknowledge my very substantial reliance of the work of Raymond Brown. The chapter in his The Birth of the Messiah that begins to treat all this is called, “Why the women?”
 This is, obviously, a matter of law, not of genetics. Perez and Zerah were “the children of Er,” who had been long dead by that point.