To David, judge me, O Lord, and plead my cause against an ungodly nation; O deliver me from the deceitful and unjust man. One verse says (Psalm 143:2), "And enter not into judgment with thy servant; for in thy sight shall no man living be justified." And another verse says (Psalm 35:23), "Judge me, O Lord my God, according to thy righteousness; and let them not rejoice over me." Rather, when you judge the righteous, do not enter into judgment with me. But when you judge the wicked, judge me, O Lord. Another interpretation: until the judgment is not yet finished, judge me. But once the judgment is finished, do not enter into judgment with me.
David Dares to Ask God to Judge Him Fairly
Midrash Tehillim 26:1