Where does the Theology of Messiah ben Joseph versus Messiah ben David come from? If we are supposed to have only one Messiah, where did the idea of these two Messias come from?
It's mentioned in the Gemara, Sukkah 52a-b. The Gemara there explains that the mourning described in Zech. 12:10ff is for Moshiach ben Yosef's death; it further identifies the "four smiths" (ibid. 2:3-4) as including "Moshiach ben David and Moshiach ben Yosef."
It is true, though, that the Rambam, in his description of Moshiach, his prerequisites, accomplishments, etc. (Laws of Kings chs. 11-12) omits the concept of Moshiach ben Yosef. This indicates that he considers this to be one of those aspects of the Final Redemption that are possible but not essential. Which means that if there is a person who fits his criteria for a potential Moshiach ("a king from the House of David who delves into Torah and observes mitzvos like his ancestor David...," ibid. 11:4) - then the fact that there wasn't a (known) Moshiach ben Yosef beforehand is immaterial.
Ovadya HaNavi seems to clearly emphasis a plurality of "saviors" in the Messianic encounter with Edom (Obadiah 1:21). Therefore while there is ultimately one king, there are others involved in the messianic redemption. Furthermore verse 18 had already emphasized the participation of the House of Yosef in the redemption.
Likewise, as Alex noted, the Gemara understands the four craftsman of Zechariah 2:4 as Moshiach ben Dovid and Moshiach ben Yosef, Eliyahu, and as the "Kohen Tzedek" (Sukkah 52b).
It is also interesting to note that while G-d had already promised Dovid HaMelech an eternal ("messianic") dynasty, when G-d gave kingship of the Northern Kingdoms to Jeroboam (who was from the tribe of Ephraim) he indicated that he too could have such a dynasty if he was obedient (1 Kings 11:38). Had Jeroboam (or other kings of the Northern Kingdom perhaps) been worthy we may really have "Two Messiahs".