• Matt 1:18-20 . . Now the birth of Jesus Christ was as follows. When His mother Mary had been betrothed to Joseph, before they came together she was found to be with child by the Holy Spirit. And Joseph her husband, being a righteous man, and not wanting to disgrace her, desired to put her away secretly. But when he had considered this, behold, an angel of the Lord appeared to him in a dream, saying: Joseph, son of David, etc, etc.
That passage confirms that Joseph was related to David. Our next step won't be so easy as it will require a bit of sleuthing; and we have to do this so that anybody can follow it rather than only seminary professors.
I've compared the genealogies given by Matthew and Luke in several different Bibles-- Catholic and Protestant, and even the Jehovah's Witnesses --in every version both genealogies are Joseph's; which is problematic because it means that Joseph had a father leading back to Solomon, and another father leading back to Solomon's brother Nathan.
If we're to accept both genealogies as true, inspired, and reliable; then I think we have to concede the possibility that one of Joseph's fathers was via birth and one was via adoption. Fortunately the Bible gives us two precedents for this situation, which, if applicable, spares us the trouble of twisting Luke 3:23 to say that it's Mary's genealogy instead of Joseph's.
It's kind of weird for kin to adopt each other's children, but Jacob did that very thing with his two grandsons Manasseh and Ephraim in Gen 48:5-6.
Manasseh and Ephraim are one example. Another is located in the book of Ruth where a boy ends up with two fathers: one by birth and one by adoption.
There's a law in the covenant that Moses' people agreed upon with God regarding men who die leaving behind no son to perpetuate their name. The man's widow is required to seek out the deceased husband's nearest unattached male kin to remarry. Their first son from the union is to be reckoned her deceased husband's posterity.
Long story short, Ruth got together with a man named Boaz and they produced a little guy named Obed. His family history is interesting because Obed is Boaz's paternal son while Elimelech's adopted son: two fathers of the same boy.
Obed was an important kid because anon he became the father of David, from whom came not only Joseph, but also Christ. (Rom 1:3)
FAQ: If Joseph wasn't Jesus' natural father, then how was the lad his son?
A: Same as above: via adoption. When it came time to circumcise the boy in accord with the law of the covenant; Joseph stood with Mary to name her baby; just as he was instructed to do (Matt 1:21-25, Luke 2:21). From that point on, Jesus was known as Joseph's son-- not only by people who knew the family, but by his mother too. (Matt 13:55, Luke 2:41-48, John 1:45, and John 6:42)