This is a very good and important question.  Since the Lord Jesus was not the biological son of Joseph, how can His heritage be validated through the genealogy of Joseph?

We have two genealogies of the Lord.  We have one in Matthew 1:1-17 and one in Luke 3:21-38.  It does not take a careful study to realize that there are several differences in these two genealogies.  In Matthew 1:16, we are told that Joseph’s father is Jacob.  In Luke 3:23, we are told that Joseph’s father is Heli. The genealogy in Matthew traces the line through David’s son Solomon (Matthew 1:6).  The genealogy in Luke traces the line through David’s son Nathan (Luke 3:31).  The genealogy in Matthew traces the Lord’s heritage back to Abraham (Matthew 1:1), while Luke traces His genealogy all the way back to Adam, through Abraham. (Luke 3:38). 

Most biblical scholars agree that these two genealogies are actually of the Lord Jesus through Joseph in Matthew, and through Mary in Luke.  This certainly explains the differences in the two.  We read in Luke 3:23, “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.”  This verse points out specifically that Joseph was not the biological father of Jesus, it was simply supposed by all that Joseph was His father. Whichever genealogy we study, they both take us back to see that the Lord was a descendent of Abraham through King David. (Matthew 1:1, Luke 3:31).  This completely affirms the Lord’s authority to be Messiah and King. 

We read in Genesis 49:10, “The sceptre shall not depart from Judah, nor a lawgiver from between his feet, until Shiloh come; and unto him shall the gathering of the people be.”  The scepter, a sign of power, was given to the line of Judah, of which David (and the Lord Jesus) was part of.  (Read Matthew 1:2 and Luke 3:33-34).  The title of ‘Shiloh’ denotes the Messiah, so we see that the proper lineage of power rightfully belonged to the Lord according to Jewish Law. 

The day will come (at the end of the 7-year Tribulation Period) when the Lord Jesus Christ will be manifested as the true and eternal KING OF KINGS AND LORD OF LORDS.  We read in Revelation 19:11-16, “And I saw heaven opened, and behold a white horse; and he that sat upon him was called Faithful and True, and in righteousness he doth judge and make war. His eyes were as a flame of fire, and on his head were many crowns; and he had a name written, that no man knew, but he himself. And he was clothed with a vesture dipped in blood: and his name is called The Word of God. And the armies which were in heaven followed him upon white horses, clothed in fine linen, white and clean. And out of his mouth goeth a sharp sword, that with it he should smite the nations: and he shall rule them with a rod of iron: and he treadeth the winepress of the fierceness and wrath of Almighty God. And he hath on his vesture and on his thigh a name written, KING OF KINGS, AND LORD OF LORDS.”  (445.6)