I'm really enjoying Kenneth Bailey's book, 'Jesus through Middle-Eastern eyes.'
In it, he shines the light of context upon Scripture's description of Joseph as a 'just man.'(Matt 1:19)
Joseph was a royal from the house of David and from Bethlehem, the City of David. In many ways he would have had the keys of the city because of his lineage. When he discovers Mary is pregnant, he knows he has every right to stone her as an adulterer by law. Understandably he feels betrayed by his pregnant bride. When scripture says he 'pondered' these things, a more accurate translation would be he 'fumed.'
Nevertheless, he does not give her what she 'deserves by law'. Bailey suggests that he knew the Isaiah 42 prophetic text about Messiah bringing a new kind of justice. "a bruised reed he will not break and a smoldering wick he will not snuff out until he establishes justice.." In many ways Mary was a bruised reed and a smoldering wick and Joseph ensured that she was not broken or snuffed out.
After the angelic confrontation, he not only spares her, but decides to identify himself as her husband, facing the risk of social rejection. It appears that Joseph was in fact rejected by his home town - no room in the inn for the royal.
That's why Joseph was called just. Often portrayed as a passive, almost invisible character, he played a decisive part in the salvation story,going beyond the law to establish a prophetic justice. A Jesus kind of justice.