Joseph and Mary from tribe of Judah
The geneology of Jesus in both Matthew and Luke's Gospel have profound truths attached to them. With that being said, we will first look at the profound truths of these geneologies and then show how Joseph and Mary both come from the same tribe of Judah as the fulfillment of Scripture.
Matthew's geneology (Mt. 1:1-16) begins the Gospel of Matthew because Matthew was intended for a Jewish audience. By starting off the Gospel with the geneology of Jesus, it proclaims the good news (Gospel) is the long awaited Promised One has arrived and his name is Jesus. Matthew emphasizes this by tracing Jesus lineage back to the Father of Faith, Abraham. He also gives 3 generations of 14 to make an emphasis on the fullfillment of God's promise. Hebrews repeated things for emphasis as they did not have superlatives like best greater, they just repeated things. This is why Jesus is often cited as saying, "Amen, Amen I say to you". He saying, this is the very important. Now getting back to the 3 sets of 14 people of generations from Jesus to Abraham (see Matt. 1:17), we must look at the Hebrew alphabet.
Ÿ Dalet (has a “D” sound and drawn like an open door) =4 (4th letter of the alphabet)
Ÿ Vav (drawn with a hook with a “v” sound) = 6 (6th letter of the alphabet)
Ÿ Transliterated its “DVD” so every time you watch a home movie you can think of the Messiah
Ÿ Add the numerical value together and what do you get 14
Remember repitition was used for emphasis so Matthew does 14 generations three times to show that the Messiah truly is from the line of David and goes back to Abraham to show how he is the fulfillment of the promise of God made to Abraham (see Gen. 22:15-18)
In Luke's Gospel (Lk. 3:23-38) we see Jesus' geneology is traced back not simply to Abraham, but to God himself. Luke was writing to the gentiles and he shows by tracing Jesus' geneology back to the first man, and then to God, that to be the perfect man is to be a Son of God.
With that being noted, we can now look and see that Joseph and Mary both came from the tribe of Judah and are descendants of King David. Here is a chart if you would like the descendant by descendant account of this lineage. The key to understanding that Joseph and Mary are both from the tribe of Judah is that it was generally Jewish law/custom for people to marry within their tribes. This was commanded by Moses in Num. 36:1-9 in order to keep the inheritance of the tribe:
The heads of the ancestral houses in a clan of the descendants of Gilead, son of Machir, son of Manasseh—one of the Josephite clans—came up and spoke before Moses and Eleazar the priest and before the leaders who were the heads of the ancestral houses of the Israelites. They said: “The LORD commanded my lord to apportion the land by lot for a heritage among the Israelites; and my lord was commanded by the LORD to give the heritage of Zelophehad our kinsman to his daughters. But if they marry into one of the other Israelite tribes, their heritage will be withdrawn from our ancestral heritage and will be added to that of the tribe into which they marry; thus the heritage that fell to us by lot will be diminished. When the Israelites celebrate the jubilee year, the heritage of these women will be added to that of the tribe into which they marry and their heritage will be withdrawn from that of our ancestral tribe.” So Moses commanded the Israelites at the direction of the LORD: “The tribe of the Josephites are right in what they say. This is what the LORD commands with regard to the daughters of Zelophehad: They may marry anyone they please, provided they marry into a clan of their ancestral tribe, so that no heritage of the Israelites will pass from one tribe to another, but all the Israelites will retain their own ancestral heritage. Every daughter who inherits property in any of the Israelite tribes will marry someone belonging to a clan of her own ancestral tribe, in order that all the Israelites may remain in possession of their own ancestral heritage. Thus, no heritage will pass from one tribe to another, but all the Israelite tribes will retain their own ancestral heritage.” (Num. 36:1-9)
So we see that the Lord Commanded through Moses that the tribes Mary within themselves. As devout Jews, Joseph and Mary would have not only known about this command, but obeyed it. Hence they both trace their lineage back to David and Judah.