The wicked is a ransom
for the righteous,
and the traitor
for the upright
- Proverbs 21:18
A few commentaries point to the account of Mordecai and Haman as an illustration of the principle set forth in this proverb. In that case, the Sovereign Lord arranged that the wicked (Haman) was a means of delivering the righteous (Mordecai). The wicked plans of Haman fell not on Mordecai as he had planned but upon himself. Thereby his very life was a ransom for the life of his hated enemy (although not on Haman’s terms).
Yet there is more to this proverb as it appears as a foreshadowing of that tremendous verse in 2 Cor. 5:21:
For our sake He made Him to be sin who knew no sin, so that in Him we might become the righteousness of God.
The righteous One gave Himself as our ransom. He took our wickedness upon Himself (made Him to be sin who knew no sin) in order to ransom those who would become right with His righteousness. This is the great exchange: The righteous given for the wicked. The righteous One becomes wicked with our wickedness (that which did not originate in Him) in order to give us His righteousness (that which did not originate in us).
And they sang a new song, saying, "Worthy are you to take the scroll and to open its seals, for you were slain, and by your blood you ransomed people for God from every tribe and language and people and nation,
- Rev. 5:9
Unlike Haman this ransoming occurred on Jesus’ terms – It was not forced upon Him but He volunteered to accomplish the ransoming of the wicked (who would thereby become righteous) by the giving of Himself, the righteous (who would thereby become wicked with our wickedness and take our curse upon Himself).
Christ redeemed us from the curse of the law by becoming a curse for us--for it is written, "Cursed is everyone who is hanged on a tree"
- Gal. 3:13