Jesus is both from the lineage of David (Yehudah) and Aaron (Levite).
Mary was a daughter of Aaron, confirmed because her cousin Elizabeth was a Levite. Mary's ancestors also served in the Temple as Kohanim (Priests).
Joseph who Mary Married, was a descendent of David!
Hence the Torah law, in Genesis 2:24
24. Therefore, a man shall leave his father and his mother, and cleave to his wife, and they shall become one flesh.
The 'one flesh' covenant relates back to Adam and Eve when Eve was created from taking Adams rib.
Genesis 1
26. And God said, "Let us make man in our image, after our likeness, and they shall rule over the fish of the sea and over the fowl of the heaven and over the animals and over all the earth and over all the creeping things that creep upon the earth."
27. And God created man in His image; in the image of God He created him; male and female He created them.
28. And God blessed them, and God said to them, "Be fruitful and multiply and fill the earth and subdue it, and rule over the fish of the sea and over the fowl of the sky and over all the beasts that tread upon the earth. "
Genesis 2
15. Now the Lord God took the man, and He placed him in the Garden of Eden to work it and to guard it.
16. And the Lord God commanded man, saying, "Of every tree of the garden you may freely eat.
17. But of the Tree of Knowledge of good and evil you shall not eat of it, for on the day that you eat thereof, you shall surely die."
18. And the Lord God said, "It is not good that man is alone; I shall make him a helpmate opposite him."
19. And the Lord God formed from the earth every beast of the field and every fowl of the heavens, and He brought [it] to man to see what he would call it, and whatever the man called each living thing, that was its name.
20. And man named all the cattle and the fowl of the heavens and all the beasts of the field, but for man, he did not find a helpmate opposite him.
21. And the Lord God caused a deep sleep to fall upon man, and he slept, and He took one of his sides, and He closed the flesh in its place.
22. And the Lord God built the side that He had taken from man into a woman, and He brought her to man.
23. And man said, "This time, it is bone of my bones and flesh of my flesh. This one shall be called ishah (woman) because this one was taken from ish (man)."
24. Therefore, a man shall leave his father and his mother, and cleave to his wife, and they shall become one flesh.
25. Now they were both naked, the man and his wife, but they were not ashamed.
Adam was created as 'them' before G-d took Eve from one of his ribs, they were one flesh. G-d created 'him' both 'man' and 'woman' but they were both in 'Adam' before G-d caused the deep sleep to fall on Adam to take one of his ribs and create Eve. That is how the one flesh convenant works, because a man becomes joined with woman before they were 'separated'. That is how Jesus fulfilled the prophecy of coming from the House of David, because Joseph was a descendant and married Mary. This also explains the 'one flesh' covenant of marriage which Jesus himself speaks about in the gospels and even Paul mentions it.
Also, there is the theory that G-d could have created Jesus in the flesh using the lineage of David. Let's see Matthew 3:9
And do not think you can say to yourselves, ‘We have Abraham as our father.’ I tell you that out of these stones God can raise up children for Abraham.
If G-d can raise up children of Abraham from stones, He can surely raise up one from David.