When Abraham was interceding with God to spare Sodom if even ten "righteous" people were there, he asked: "Shall not the Judge of all the earth do right?" (Genesis 18:25). The Hebrew word (mishpat) refers to a formal judgment about right and wrong and is more commonly translated "judgment."
Indeed, the divine Judge will do right and give right judgments in all things, for He "is righteous in all his ways" and "canst not look on iniquity" (Habakkuk 1:13).
Ever since Adam disobeyed the Word of God, however, all his descendants have been unrighteous in their ways. God's righteous judgment has been that "there is none righteous, no, not one" (Romans 3:10).
Thus a truly righteous Judge would not only have to consign Sodom to destructive "brimstone and fire from the LORD" (Genesis 19:24), but every one of us as well "into the lake of fire" (Revelation 20:15) forever.
But God, being not only the righteous Judge, but also "a faithful Creator" (1 Peter 4:19), had a plan whereby He could "declare his righteousness for the remission of sins that are past" and both "be just, and the justifier" of those who had been lost sinners (Romans 3:25-26). "God sending his own Son in the likeness of sinful flesh, and for sin, condemned sin in the flesh" (8:3). Those who believe on the Son of God as their substitute and Savior are now "justified freely by his grace through the redemption that is in Christ Jesus" (3:24).
So, Christ has been "made unto us . . . righteousness" (1 Corinthians 1:30). Furthermore, our loving Savior has now Himself become our righteous Judge, for "the Father . . . hath committed all judgment unto the Son" (John 5:22). HMM