Matthew 1:16 - And Jacob begat Joseph, the husband of Mary…
Luke 3:23 - Jesus…being (as was supposed) the son of Joseph, which was the son of Heli.
Joseph is the son of Jacob (who “begat” him), but is the son-in-law of Heli (who would be the person who “begat” Mary).
You don’t just marry your spouse, you marry your spouse’s entire family as well. Thus, Joseph can be called the son of Heli, even though Heli did not beget Joseph.
The genealogy in Matthew is the line of Joseph, the line of legal inheritance, because the legal reckoning is through the males. The sons are the ones who inherit their father’s land and property and business, and the firstborn gets a double share. The daughters marry into the families of their husbands and are no longer the direct responsibility of their fathers or their brothers and share in the inheritance of their husbands. (Leaving and cleaving.) (See Numbers 30 to see that the father and the husband have the final word over the decisions of the wife or daughter.) (See also Ephesians 5:22 “Wives submit yourselves to your own husbands, as unto the Lord.”)
This line is traced back only to Abraham, because he was the Father of Many Nations, but most importantly he was the father of Nation of Israel.
The genealogy in Luke is the genealogy of Mary. It is traced back all the way to Adam. But you will notice that she is also a direct decendant of David, though not through the Kingly line of Solomon, as is Joseph. Why? – Jeremiah 22:30: [The LORD, speaking of Coniah, the son of Jehoiakim (verse 24), the last king of Israel before the deportation by Nebuchadnezzar.] “Thus saith the LORD: Write ye this man childless, a man that shall not prosper in his days, for no man of his seed shall prosper, sitting on the throne of David, and ruling any more in Judah.”
Joseph, therefore (Matthew 1:11), is a descendant of Soloman and Jechonias (AKA Coniah) and therefore a son of his (Joseph’s) seed could not be sitting on the throne of David. But Jesus is his “adopted” son, the firstborn, the one who is entitled to the inheritance. Not just the first in time, the first in importance. Therefore, Jesus legally is a descendant of David, through Solomon, and even Coniah, and is entitled to sit on the throne of David, but He is not a direct blood (DNA) descendant of Coniah, because no descendant of Coniah is allowed to sit on the throne of David.
Mary, however, is a descendant of Nathan (Luke 3:31), Solomon’s brother. Therefore Jesus is a direct boodline (DNA) descendant of David and as such is entitled to sit on the throne of David. Mary’s genealogy goes back all the way to Adam to establish Jesus’ claim to be the “son of man,” in addition to being the Son of God.