Details about him are not found until much later, but he has an established place in the apocalypses of later centuries, such as the Apocalypse of Zerubbabel, and in the midrash literature—in Saadia’s description of the future (Emunot we-De’ot, ch. viii.) and in that of Hai Gaon (Ṭa’am Zeḳenim, p. 59). According to these, Messiah b. Joseph will appear prior to the coming of Messiah ben David; he will gather the children of Israel around him, march to Jerusalem, and there, after overcoming the hostile powers, reestablish the Temple-worship and set up his own dominion. Thereupon Armilus, according to one group of sources, or Gog and Magog, according to the other, will appear with their hosts before Jerusalem, wage war against Messiah ben Joseph, and slay him. His corpse, according to one group, will lie unburied in the streets of Jerusalem; according to the other, it will be hidden by the angels with the bodies of the Patriarchs, until Messiah ben David comes and resurrects him (comp. Jew. Encyc. i. 682, 684 [§§ 8 and 13]; comp. also Midr. Wayosha’ and Agadat ha-Mashiaḥ in A. Jellinek, B. H. i. 55 et seq., iii. 141 et seq.).
This is from the Wikipedia article on the Messiah ben Joseph. While the wiki article says that it’s unknown where these “two messiahs” tradition comes from, there’s actually a prescedent for it found in the Dead Sea Scrolls, which predate both the Jesus of Christianity and Rabbinic Midrash.
Before getting to that though, here is Zechariah 4:11-14
Zechariah 4:11-14 (New International Version)
11 Then I asked the angel, “What are these two olive trees on the right and the left of the lampstand?”
12 Again I asked him, “What are these two olive branches beside the two gold pipes that pour out golden oil?”
13 He replied, “Do you not know what these are?”
“No, my lord,” I said.
14 So he said, “These are the two who are anointed to serve the Lord of all the earth.”
I should note that the word for “anointed” here, at least in the LXX which I can read better than Hebrew, is not christ and doesn’t have any grammatical relationship to the verb ΧΡΙΩ::chrio (I anoint) from where the noun ΧΡΙΣΤΟΣ (christ) comes from. So it might not refer to any sort of “messiah”. But it is still fishy.
There’s also Jeremiah 33
17 For thus saith the LORD: There shall not be cut off unto David a man to sit upon the throne of the house of Israel;
18 neither shall there be cut off unto the priests the Levites a man before Me to offer burnt-offerings, and to burn meal-offerings, and to do sacrifice continually
Here we have a root from David (kingly) and a root from the Levites (priestly).
In the Qumran community (popularly referred to as the Essenes), from before the Christian era, their “Damascus Document” (CD) has a possible reference to two messiahs. The phrasing says “anointed of Aaron and Israel” (CD 12:23-13:1) hinting at a priestly (Aaron) messiah and a separate kingly (Israel) messiah. In 4QFlor 10-12 it says “He is a branch of David who will arise with the interpreter of the law who shall arise with Zion in the last days”. Here we have again the branch of David and a separate personage who is an interpreter of the law. Implying that this secondary messiah is a priest.
I should point out a little history of this Qumran group. They came into being due to the Maccabean rebellion where the “legitimate” priestly line was kicked out by the Maccabees because this priestly line allowed the “abomination causing desolation” to stand where it didn’t belong. The ensuing revolt of the Maccabees not only incited rabid monotheism among the Jews, but removed the prior priestly line, ousted Greek hegemony, created the celebration of Hannukah, and led to the destruction of the Samaritan temple (of course, the Jews themselves would suffer a similar fate with their temple almost 200 years later at the hands of the Romans).
The Qumran group reviled the ousting of the high priest, so their writings are highly “sectarian” and might not be representative of mainstream Judaism (but neither was Christianity). Their focus was on returning to the glory of the legitimate priestly line, not the ones set up by the Maccabees. Therefore, their messainism and eschatology would include both a king and a legitimate priest to replace the illegitimate priests of the Maccabees/Hasmoneans and those newbie Sadducees.
Now I hypothesize that the earliest Christians knew of both of these messiahs. One a son of David, and the other a son of Joseph. Obviously in the gospel narratives, Jesus is referred to as both. He’s of the lineage of David, but is also the son of “a” Joseph. Thirdly, he is also the son of god. I see this as an attempt by Christians to harmonize the various messainisms of Judaism (son of both David and Joseph) and Greek/pagan views of authentic kingship (being a son of god).