From 40 Questions About Christians and Biblical Law, by Thomas R. Schreiner, in the section on justification, on the Old Testament background for the righteousness of God:
It is … instructive to note that righteousness in the Old Testament is often forensic in nature. For instance, Deuteronomy 25:1 presupposes that judges will “acquit the innocent and condemn the guilty” (my translation). Clearly, the judges do not make a person righteous or guilty but declare whether the person under trial is innocent or guilty. God himself says that he “will not acquit the wicked” (Exod. 23:7), which means that he will not declare the wicked to be in the right. Similarly, Proverbs 17:13 declares, “He who justifies the wicked and he who condemns the righteous are both alike an abomination to the Lord.” …. What is evident here is that judges do not make someone righteous or wicked. They render a forensic declaration based on the reality that is before them. Unrighteous judges “acquit the guilty for a bribe” (Isa. 5:23; cf. 2 Sam. 15:4). God’s righteousness as a judge is explained in Solomon’s prayer as “condemning the guilty by bringing his conduct on his own head and vindicating the righteous by rewarding him according to his righteousness” (1 Kings 8:32).
Schreiner goes on to list several more places in Job and Isaiah that show the forensic character of righteousness, concluding that while the word righteousness can carry a few different meanings in the Old Testament, frequently referring to God’s “saving righteousness by which he delivers his people because of his steadfast love,” it “is often forensic, addressing whether the defendant is innocent or guilty before the divine judge.”