A couple of interesting notes on this:
Apparently a baby's blood comes only from the father and not the mother. Apparently food and waste is transferred in the placenta but no blood from the mother. The blood of Christ was purely from the Father and not from Mary.
Also, as you may know, the four beasts in Revelation 4:7 are the revelation of the four pictures of who Jesus is and corresponds to the four gospels. Matthew reveals Jesus as the Lion of the Tribe of Judah, in Mark he is the working ox or calf, in Luke he is revealed as the Son of man, and in John he is the Son of God who will return as a flying eagle. So Jesus, as the Lion of the Tribe of Judah in Matthew, is shown though Joseph's line of kings as you point out. In Luke, Jesus, as the Son of man, is shown through Mary's line from which which Jesus' actual human flesh came. How wonderful is our God!
We could speculate a lot on “implementation details” of what is a one of a kind occurrence, a miracle as frank as any since before the start of creation. That might or might not be enlightening, but the discussion should always be kept within the realm of charity. We can count on what the bible shares with us.
As mentioned earlier, the line of David was not perfect. There were those who greatly disobeyed God. Even David himself had sinned greatly. However God in his great mercy forgave and restored David, and ensured that his line will provide us the great Messiah-King.
There are four women (other that Mary) mentioned in Matthew 1. Kind of unusual that many women are mentioned from a genealogy from those days. It is interesting to consider their backgrounds- especially considering that this is the genealogy of the Messiah-King, and God found it worthy to mention them in the line of His Son. Two of the women, Rahab and Ruth were gentiles. Tamar and Rahab were harlots, and Bathsheba had committed adultery with David. It sort of speaks to us of Christ bringing salvation to sinners, grace to the gentiles. Race, gender, background are not obstacles to come to Him.
The genealogy ends with Mary in verse 16. It speaks to us of Christ as the Seed of the Woman.