"And Joseph was brought down to Egypt" (Genesis 39:1). This is what Scripture said: "For the LORD loves justice and does not forsake His pious ones" (Psalms 37:28). Why does the Holy One, blessed be He, love justice? Because He is called the Master of Justice, as it is said, "For the LORD is a God of justice" (Isaiah 30:18). And it says, "and My hand takes hold on justice" (Deuteronomy 32:41).
Why God Loves Justice When Joseph Goes Down to Egypt
Midrash Tanchuma Buber, Vayeshev 14:1
ויוסף הורד מצרימה (בראשית לט א), זש"ה כי ה' אהב משפט ולא יעזוב את חסידיו (תהלים לז כח), למה הקב"ה אהב משפט, שהוא נקרא בעל המשפט, שנאמר כי אלהי משפט ה' (ישעיה ל יח), ואומר ותאחז במשפט ידי (דברים לב מא).