I know I might get downvotes, but since this website claims to be academic, I think this answer should be included.
Some modern critical scholars like Marcus Borg and John Dominic Crossan state that both genealogies are inventions, intended to bring the Messianic claims into conformity with Jewish criteria.
(Marcus J. Borg, John Dominic Crossan, The First Christmas (HarperCollins, 2009) page 95.)
About whether tribal identity passed by adoption, the answer is no.
Only the biological father passes tribal identity. In some certain cases, when we do not know the father's identity, the child is called Shetuki (like literally 'shut up' your mouth when someone asks about your father).
There is no way that a boy that apparently born to a virgin will get the identity of his adopting father. In the Torah, there is the case of the son of Shlomit Bat Divri, that sages explain that the tribe of his mother rejected him, for not being of their tribe. So this egyptian man did not belong to any of the tribes. This proves that tribal identity do not pass through the mother.
You can see the definition of Shetuki in the Mishnah:
עֲשָׂרָה יוֹחֲסִין עָלוּ מִבָּבֶל, כַּהֲנֵי, לְוִיֵּי, יִשְׂרְאֵלֵי, חֲלָלֵי, גֵּרֵי, וַחֲרוּרֵי, מַמְזֵרֵי, נְתִינֵי, שְׁתוּקֵי, וַאֲסוּפֵי. כַּהֲנֵי, לְוִיֵּי וְיִשְׂרְאֵלֵי, מֻתָּרִים לָבֹא זֶה בָזֶה. לְוִיֵּי, יִשְׂרְאֵלֵי, חֲלָלֵי, גֵּרֵי וַחֲרוּרֵי, מֻתָּרִים לָבֹא זֶה בָזֶה. גֵּרֵי וַחֲרוּרֵי, מַמְזֵרֵי וּנְתִינֵי שְׁתוּקֵי וַאֲסוּפֵי, כֻּלָּם מֻתָּרִין לָבֹא זֶה בָזֶה:
There were ten categories of lineage, with varying restrictions on marriage, among the Jews who ascended from Babylonia to Eretz Yisrael with Ezra before the building of the Second Temple. They are as follows: Priests; Levites; Israelites; priests disqualified due to flawed lineage [ḥalalim]; converts, and emancipated slaves; mamzerim; Gibeonites, i.e., the descendants of the Gibeonites who converted in the time of Joshua; children of unknown paternity [shetuki]; and foundlings. The mishna proceeds to detail their halakhot: With regard to priests, Levites, and Israelites, it is permitted for men and women in these categories to marry one another. With regard to Levites who are not priests, Israelites, ḥalalim, converts, and emancipated slaves, it is permitted for men and women in these categories to marry one another. With regard to converts, and emancipated slaves, mamzerim, and Gibeonites, children of unknown paternity [shetuki], and foundlings, it is permitted for all of the men and women in these categories to marry one another.
https://www.sefaria.org/Mishnah_Kiddushin.4.1
וְאֵלּוּ הֵם שְׁתוּקֵי, כֹּל שֶׁהוּא מַכִּיר אֶת אִמּוֹ וְאֵינוֹ מַכִּיר אֶת אָבִיו. אֲסוּפֵי, כֹּל שֶׁנֶּאֱסַף מִן הַשּׁוּק וְאֵינוֹ מַכִּיר לֹא אָבִיו וְלֹא אִמּוֹ. אַבָּא שָׁאוּל הָיָה קוֹרֵא לִשְׁתוּקֵי, בְּדוּקֵי:
And these are the last two categories: A shetuki is any person who knows the identity of his mother but does not know the identity of his father. A foundling is anyone who was collected from the marketplace and doesn’t know the identity of his parents, neither that of his father nor that of his mother. These two categories are people whose status is uncertain; they may be mamzerim. Abba Shaul would call a shetuki by the label of beduki.
https://www.sefaria.org/Mishnah_Kiddushin.4.2
Final words,
It seems that those who wrote the lineage of Jesus, were unware of jewish law, so it is very likely that these are inventions. According to jewish law, Jesus could marry only a woman from the lowest lineage category.
Of course, the motive to invent these lineages, might be to get out of people's mind, that Jesus was an ilegitimate child, Which was the common belief in his time.
One last point. If you would discover, that Joseph had no blood relation to king David, do you think it would affect the essense of Jesus? Would it contradict, in your eyes, that Jesus was the Messiach?