ANSWER: For Jesus to qualify as the Messiah, as you correctly stated, he had to be not only a Jew but also be descended from King David, who came from the tribe of Judah (Luke 1:32). As an interesting side note, the term Jew was originally used only for those who were the descendents of Judah (one of Jacob's sons).
When the united kingdom of Israel split after the death of Solomon in 930 B.C. it broke up into two major parts. The southern part of the kingdom, composed of three tribes, became the Kingdom of Judah. The term Jews, sometime after the break, began to be used as "shorthand" for anyone who lived in the southern kingdom.
Your inquiry assumes that it is the lineage of a person's father (in the case of Jesus, his stepfather Joseph) that determines whether or not they are considered a Jew. The Biblical truth is that the descent of the mother, in this case Mary, is more important in determining whether a child is considered Jewish (in this case, springing from the tribe of Judah) than that of the father. For example, a baby born with a mother from the tribe of Judah and a father who is a Gentile (non-Israelite) would be considered a Jew. A baby produced, however, through a father who is from the tribe of Judah and a mother who is a Gentile (non-Israelite) would not.
Doubts about the true parentage and lineage of Jesus abounded in the first century, as most people doubted and even rejected the idea that he could have be born from a virgin (even the Pharisees subtlely accused him of being born illegitimately, see John 8:41).
How can we prove the lineage of Jesus qualifies him to be the Messiah if the Hebrews, in general, did not include women in their genealogical tables? The answer is that the gospel writer Luke resorted to a little 'trick' in order to record that the bloodline of Jesus, through Mary, went all the way back to King David (a Jew), then Judah, and then all the way back to Adam.
Luke begins tracing our Savior's physical line through Mary by stating her husband, Joseph, was the son of Heli (Luke 3:23). Joseph's father, however, according to the book of Matthew (Matthew 1:16), is not named Heli but JACOB. Heli is the name of MARY'S father (the father-in-law of Joseph). Luke uses Joseph's name to represent, symbolically, Mary in the lineage he records. Jesus, therefore, is a Jew, through the tribe of Judah, by blood through his mother.
The book of Matthew, chapter 1, traces the descendants of Abraham to Judah, then to King David, then to Joseph. What does Matthew's lineage show since, as you rightly state, the REAL Father of Jesus was God in heaven (Matthew 1:18, 20, Luke 1:34 - 35)? It shows our Savior's LEGAL lineage, which means he has a legal right to be considered a son of David. This claim is asserted in the very first verse of the New Testament which states, "The book of the genealogy of Jesus Christ, THE SON OF DAVID, the son of Abraham" (Matthew 1:1).
The pedigree of our Savior Jesus is also asserted in other places in the New Testament such as Romans 1:2 - 3, which states he came from the seed of David. In Hebrews 7:14 it emphatically states, "For it is quite evident that our Lord has descended from Judah, of which tribe Moses spoke nothing concerning the priesthood" (see also Acts 13:22 - 23). Jesus is both, by blood and legally, a Jew and a descendant of King David. It was Joseph's lineage back to David that forced him and a very pregnant Mary to travel to Bethlehem.