"For our sake He made Him to be sin who knew no sin, so that in Him we might become the righteousness of God." ~2 Corinthians 5:21
Jesus lived a perfect life. He did not know sin because He could not sin. Jesus is perfect. Jesus is God. But so we could become righteous, Jesus who knew no sin became sin for us by dying the death we deserved on the cross. He suffered so much so that we could know the righteousness of God and actually become righteous as He is righteous.
Though, we are sinners, in Christ we can become righteous! What a gift.