God displays his righteousness by judging sin as sin deserves, but the judgment is diverted from the guilty and put on to the shoulders of Jesus Christ, the sinless Son of God acting as wrath absorber.
The atonement had to be costly because it was necessary in light of the nature of God, which must inflict retributive punishment on sin.
A marvelous wisdom of God consists in his establishing the Lord Jesus as our representative and our substitute because only he could bear and absorb the judgment due to us. Being our representative makes him our substitute, and so he suffers and we go free.
“The Necessity of the Atonement” in Atonement, ed. Gabriel N. E. Fluhrer (Phillipsburg, NJ: P & R Publishing, 2010), 15-16
(HT: Of First Importance)