 He emulates the nature of God in his goodness. That's tzaddik. And tzedakah is that virtue of righteousness. Joseph was a righteous man who did not want to subject the Blessed Mother to the penalty of the law.