Why is Jesus' genealogy in Matthew and Luke traced back to David through Joseph if Jesus was conceived by the Holy Spirit?
First of all, Joseph was not Jesus biological father in any understanding since Mary conceived by a miraculous intervention of the Holy Spirit before she was joined to Joseph and the text tells us they refrained from intercourse until after Jesus birth.
However in the eyes of the law of the time, Joseph was the father. More than just a legal guardian, by later taking Mary as his wife, he also claimed Jesus as his son. This gave him a standing in relation to the child that -in the eyes of the Jews at least- must be accounted for. The fact that he was himself of the line of David would put many doubts about the validity of Jesus' claims to rest. The excuse that there was no blood relation would have been overshadowed by the fact that he was the lawful father and not himself of the prophesied linage.
Knowing that Joseph was himself of the line of David makes Jesus the rightful legal heir to the throne of David even though he wasn't biologically related to his earthly father.
Secondly, there is actually a huge difference between the genealogies found in Matthew and Luke. If you read them, there are only a couple names in common from David to Jesus. One possibility for this is that Joseph had two fathers: one legal and one biological through a Levirate marriage (where the brother of a man with no offspring would step in to provide one).
However the other idea that many scholars agree on is that the record found in Luke is actually a trace of Mary's family tree. It wasn't common to trace the maternal side, but then again the virgin birth was hardly a normal occurrence! This would mean we have both the paternal and maternal genealogies and all the bases are covered.
Short answer: because both the right to be king (which Matthew traces) and the legal guardianship (which Luke traces) came through the father.
Long answer: Matthew's genealogy is traced through the right to be king. A theme in Matthew is the kingship of Jesus. This starts in ch1, where Jesus is called the "son of David" (Mat 1:1) - Joseph is called the "son of David" only a few verses later (Mat 1:20). Matthew's emphasis here is that Jesus, the legal (not biological) son of Joseph, was counted as a son of David because Joseph was a son of David. This phrase harks all the way back to 2Sam 7:12-14, which say that David's "seed" will be set up as a king and established forever, and be God's son. Though this prophecy may be partially fulfilled by a few Old Testament kings, it is completely fulfilled in the Messiah. This prophecy can be traced through the Old Testament in places like Is 11:1 (talking about the "stem of Jesse" [Jesse was David's father] producing the Messiah who would reign), cf. Is 16:5, Jer 33:15-17. This phrase "the son of David" is therefore used as a synonym with "Messiah", emphasizing Jesus' right to rule - the phrase is used more times in Matthew than in the rest of the New Testament combined (Mat 1:1, 20, 12:23, 15:22, 20:30, 31, 21:9, 15, 42). Note also Matthew's emphasis on David's kingship in his genealogy in 1:6 - an emphasis found in none of the other kings in Matthew's genealogy.
This theme of Jesus' kingship, which starts with the term "son of David", can be traced through Matthew as the wise men worship him as king of the Jews, as Jerusalem is told, "behold, thy King is coming, lowly and sitting upon a donkey", as Jesus at his trial admits to being the king of the Jews (Mat 27:29), and even as this same epithet is written over the cross as he dies. The kingship theme in Matthew is undeniable.
Because of this emphasis on "the son of David" and kingship in Matthew, the trace of any genealogy but through the line of kings would be surprising. Moreover, one of the people in the genealogy, Jehoiachin (Matthew calls him "Jeconiah"; he is also called "Coniah"), had no children: Jer 22:30, "write this man down as childless". Thus the genealogy cannot have been biological. But as the right to be king passed from this childless man to the next man in line, a a genealogy tracing kingship rather than genes has no problems with a man having no children - the genealogy simply skips to the next man in line for kingship.
Luke's genealogy is traced through legal parenthood.
Sorry, gotta go. If I have time, I'll finish the answer later - or make it a wiki, and someone will finish it for me.
Jesus' genealogy is traced through Joseph because:-
Adoptive sons in the first century had all the same rights of inheritance as biological sons in both Jewish law and Roman law, and that inheritance was from father to son;
If the house of David were still ruling then Joseph while he lived was the King of Israel being first in line to the throne of David, and, when Joseph died, Jesus, being his oldest son, became the King of Israel;
To fulfil the prophecy of 2 Samuel chapter 7, that a descendant of David would sit on the throne for ever, and David's house (dynasty) would be established for ever:
And the LORD tells you that he will make you a house. And when your days be fulfilled, and you sleep with your fathers, I will set up your seed after you, who shall proceed out of your bowels, and I will establish his kingdom.... And your house and your kingdom shall be established for ever before you; your throne shall be established for ever. 2 Samuel 7 verses 11,12 & 16.
- The legally binding records of descent were through the male line, with the name of the son and his father's name being recorded in the public records which were kept in Jerusalem near the Temple, and were most likely added to at the time of circumcision of the baby boy. These records of genealogical descent formed an important part of the public records and were needed to establish rights of inheritance, particularly land rights in this mainly agricultural society. They also established that the boy was a descendant of Jacob, and could enjoy the privileges of being a member of the covenant people of God, the covenant God had made with Abraham, Isaac and Jacob.
(Furthermore, had ancient Judaea fully implemented the laws of the Pentateuch the genealogical records would have been needed in the Year of Jubilee, every 49 years, so that land could return to the correct individual according to original tribal/clan and family allocations of the land (Leviticus 25:28).)
But Jesus's genealogy is not traced just through Joseph...
The above Scripture predicts that the King who will sit upon the throne of his father David for ever will "proceed out of his own bowels", meaning he will be a biological descendant of David.
Seeing as Mary gave birth to Jesus while a virgin it follows that he was not of biological descent through Joseph. It is therefore inevitable that the descent of Jesus from David must be recorded twice in the New Testament, once through Joseph (to establish Jesus's right to the throne of David) and once through Mary (to prove his biological descent from David).
Matthew's genealogy of Jesus is clearly via Joseph, so Luke's genealogy must be that through Mary.
The critical verse is:-
And Jesus himself began to be about thirty years of age, being (as was supposed) the son of Joseph, which was the son of Heli, (Luke 3:23)
which could be written thus:-
"And Jesus himself began to be about thirty years of age, (being as was supposed the son of Joseph,) which was the son of Heli,"
not meaning Joseph "was a descendant of Heli" but Jesus was a descendant of Heli and
where Heli is the father of Mary, and the nearest man to being Jesus's biological father.
In other words the meaning is thus:-
And Jesus himself began to be about thirty years of age, (being as was supposed the son of Joseph,) (but) which was (actually) the son of Heli
Mary's name is missed out because, as was said before, it was not the practice to include a line of descent through any female, so it is simply following convention to leave out her name.
The public records mentioned above are also spoken of by Flavius Josephus in the last sentence of the first chapter of his autobiography:-
Thus have I set down the genealog of my family as I have found it described (2) in the public records, and so bid adieu to those who calumniate me [as of a lower original]. ( https://sacred-texts.com/jud/josephus/autobiog.htm )
In that Josephus refers to these records and yet does not say they were destroyed during the first Jewish rebellion (66-70 CE) this suggests they still existed after 70 CE. While under Roman authority these public records would have been under Roman bureaucratic control. It is to the legally binding public records in Jerusalem that both Matthew and Luke must have resorted to produce their genealogies of Jesus. The enemies of Jesus only had to prove from the public records that Jesus of Nazareth was not a descendant of David to prove he was not the Messiah. Any attempt by them to do this is not recorded, which begs the question... did they attempt to get evidence but find instead the opposite of the evidence they wanted?
Of course, these public records no longer exist, and so no one living today can legally prove they are even a descendant of David, let alone prove they are in direct line to the throne of David.