That . . .--So that (or, in order that) thou art (or mayest be) justified in thy cause, and clear in thy judgment. The Hebrew, rendered in the Authorised Version when thou speakest, is often used of a cause or suit (see (Exodus 18:16-22, "matter," &c), and it is here plainly used in this sense and is parallel to judgment. The clause seems to imply not only a sense of a breach of the covenant, but some manifest judgment from Jehovah in consequence; and, as usual, it is of its effect on the heathen that the psalmist thinks. The Divine honour would be justified when the suffering nation confessed that condemnation and punishment had been deserved. This was apparently the meaning read in the words by the LXX.
and done this evil in thy sight; for with respect to men it was secretly done; and was only known to God, with whom the darkness and the light are both alike;
that thou mightest be justified when thou speakest, and be clear when thou judgest; not that David committed this sin that God might be just, and pure, and holy; but this was the event and consequence of it: God, by taking notice of it, resenting it, and reproving for it, appeared to be a righteous Being, and of purer eyes than to behold sin with pleasure; see Exodus 9:27. Or these words may be connected with his acknowledgment and confession of sin; which were done to this end and purpose, to justify God in his charge of it upon him, and in threatening him with evils on account of it, by the mouth of Nathan the prophet: or with his petitions for pardoning grace and mercy; that so he might appear to be just to his promise, of forgiving iniquity, transgression and sin, to humble penitents; and particularly that he might appear to be just and faithful to his Son, in forgiving sin for his sake; whom he had set forth, in his purposes and promises, to be the propitiation for sin, to declare his righteousness, Romans 3:25; see Romans 3:4.