Psalm 18 forms a chiastic structure:
1a) Psa 18:1-3, God is my deliverer;
1b) Psa 18:4-6, I cried out to God and He heard me;
1c) Psa 18:7-19, God’s might in warfare;
1d) Psa 18:20-24, My righteousness;
central axis) Psa 18:25-27, “With the merciful You will show Yourself merciful; with a blameless man You will show Yourself blameless; with the pure You will show Yourself pure; and with the devious You will show Yourself shrewd. For You will save the humble people, but will bring down haughty looks;”
2d) Psa 18:28-30, God’s grace;
2c) Psa 18:31-40, God’s empowerment of my might for warfare;
2b) Psa 18:41-42, My enemies cried out to God, and He did not hear them;
2a) Psa 18:43-50, God is my deliverer.
What I find most interesting about this structure, and this is sometimes the way the Scripture teaches us, is that the D pairs don’t seem at first glance to fit. But since it is in the middle of a structure where the rest of it is undisputed, thus they have to be paired together, it causes us to try to find the common theme for them both.
Have you noticed that this is a teaching tool of Scripture? It creates a puzzle, then invites us to solve it?
The 1D pair is clearly talking about David’s righteousness and the cleanness of his hands and the integrity of his heart. He also tells why he was righteous and clean: he kept the ways of the Lord. The Lord’s ways are revealed to us in the form of judgments and statutes; i.e., the Law, the Torah (that which casts forth rain to produce fruit). David did not sin. Scripture is teaching us the same lesson that Gen 1-3 taught us, that sin = disobedience to God’s commandment(s), and righteousness = obedience to God’s commandment(s).
How does the 2D pair fit?
For You will light my lamp;
The LORD my God will enlighten my darkness.
For by You I can run against a troop,
By my God I can leap over a wall.
As for God, His way is perfect;
The word of the LORD is proven;
He is a shield to all who trust in Him. Psa 18:28-30
The 1D pair was what David did. The 2D pair is what God does. To light a lamp is to enlighten the darkness. This is something that God does, not us. He makes us light. AFTER He makes us light, He gives us power, and we begin to discover the excellency of His ways and His word.
Another way the Gospel of grace is revealed is this: He is a shield to all who trust in Him. Do you notice that the Scripture never talks about working righteousness, without also talking about what we cannot work, what must be grace through faith?
The LORD rewarded me according to my righteousness;
According to the cleanness of my hands He has recompensed me. Psa 18:20
This verse (and others like it) are the ones we like to gloss over, and if we were writing the Bible, I am sure we would leave them out. Listen, working sin carries with it consequences of destruction. Working obedience carries with it consequences of blessing. We teach this to our children, as God is teaching it here to His children.