2 Corinthians 5:21 says: “God made him who had no sin to be sin for us, so that in him we might become the righteousness of God.” (NIV)
God’s Word, the Bible, tells us that Jesus knew no sin (2 Corinthians 5:21), committed no sin (1 Peter 2:22) and in Him is no sin (1 John 3:5). Jesus did not deserve to be punished for sin, because He was and is sinless. But nevertheless, God punished Him and made Him sin. Why? So He could make us the righteousness of God.
We didn’t deserve it; we can’t earn it. We simply receive it. Just like Jesus was made sin for us; we are made righteous because of Him. We will never be able to earn it or deserve it; it is simply for us to joyfully receive.