God governs the world through a precise system of measure for measure, mirroring a person's character and actions in His response to them. When an individual lives with purity and clarity, God responds in kind, treating them with clear goodness and mercy. This dynamic is deeply personal to King David. Throughout his life, David often went beyond the strict requirements of the law, choosing to forgive his enemies. A defining moment of this grace occurred when he spared King Saul's life in a cave instead of taking revenge. Because David acted with such extraordinary mercy, God rewarded him measure for measure, choosing to establish David's kingdom permanently. This stands in sharp contrast to Saul, who rigidly adhered to the strict letter of the law [רש״י, אהבת יהונתן, אברבנאל].
Conversely, those who act with deceit face an entirely different divine response. When a person chooses a crooked and twisted path, God interacts with them in a similarly convoluted manner. He uses their own twisted methods against them, ensuring they stumble in their wickedness and face punishment [רד״ק, מצודת ציון, אברבנאל]. A primary example of this ultimate form of divine retribution can be seen in God's dealings with Pharaoh [רש״י].
This song of David is recorded twice in the Bible—once in the historical account of his life and again in the Book of Psalms. When David originally sang these words, he naturally shortened certain expressions to maintain the rhythm and musical flow of his live performance. Later, when the song was formally recorded in Psalms, the language was expanded into its complete and precise form [רד״ק, אברבנאל, מנחת שי].