What is Joseph’s theological role in Matthew’s gospel? It should be noted, first, that Joseph is explicitly called a "righteous man" (Mt. 1:19). His righteousness, moreover, is implicit throughout the first chapters of the gospel. He responded to the angel’s explanation of Mary’s pregnancy by marrying her, as the angel had instructed (1:24-25). When commanded to leave Bethlehem to flee to Egypt, he "arose and took the CHild and His mother by night, and departed for Egypt" (2:14). When told to return to Israel, he returned, despite apparent misgivings about the safety of the return (2:19-23). Joseph, like Mary in Luke’s gospel, responded with immediate submission and obedience to the command of the angel of the Lord.
Second, Joseph is identified as Mary’s husband (1:16, 19). A husband in Scripture is a priest. God Himself is the Husband of His people (Is. 54:5; Ezk. 16:32; Eph. 5:22-33), and the priest, as His special officers and images, are to share in the husbanding task of protecting the bride. Joseph’s importance as the priest-husband comes into sharper relief when we recall that Mary, the Virgin, represents the faithful remnant of Virgin Israel (cf. my essay, "The Virgin Birth: A Redemptive-Historical Interpretation"). If Mary represents the virgin remnant in the midst of prostituted Israel, Joseph represents the faithful remnant of priests within Israel.
Joseph thus showed how Israel’s leaders should have acted if they had been righteous husbands of the Bride. He fulfilled his role as priest-husband in two ways. First, when he found that Mary was pregnant, like Eli the priest when he saw Hannah praying, he suspected the worst. This was hardly surprising, given the condition of Israel at the time. In the context of Matthew’s genealogy, Joseph’s suspicion are given an additional dimension: the women of the genealogy were all in some way scandalous (with the exception of Ruth). Joseph suspected that Mary was a Tamar or a Bathsheba. In response, Joseph plans to put Mary away privily to avoid shame. Instead of exposing the "nakedness" of his (supposedly) unfaithful bride, he seeks to cover her nakedness (cf. Ezk. 16:8; Hos. 2:8-9; Rev. 3:18).