God made him who had no sin to be sin for us, so that in him we might become the righteousness of God. 2 Cor 5:21Paul says in Romans 1:17 that in the gospel a certain righteousness is revealed. It's not man's righteousness. It's God's righteousness. The gospel reveals God's righteousness that is given to man as a gift. Paul spends the rest of Chapter 1, and then Chapter 2 and over half of Chapter 3, making the case for man's unrighteousness. He does this to show how ALL have sinned and fallen short of the glory of God. Finally near the end of Chapter 3 he gets to what he was really leading up to: "But now the righteousness of God apart from the law is revealed, being witnessed by the Law and the Prophets, even the righteousness of God, through faith in Jesus Christ, to all and on all who believe."
The law and the prophets were witnesses to this righteousness, but it's made clear in the gospel that man's attempts at righteousness, no matter how "good" or how "bad," ended up falling way short. And so: the gift of righteousness.
A little bit later Paul writes, "For as by one man's disobedience many were made sinners, so also by one Man's obedience many will be made righteous" (Rom 5:19). You were not declared a sinner because you committed sinful acts. You were made a sinner "by one man's disobedience." Even when you did "good," you were still a sinner.
In the same way, you are not righteous because of any righteous act or acts you have ever done. You are now declared righteous because you've been raised up together with Jesus, through faith. In the same way that you previously inherited sin, you've now inherited righteousness. Even when you do "bad," you are still righteous.
It's been given to you as a gift, and you can't earn gifts! To earn a gift is not only oxymoronic, it's moronic! Many Christians walk in fear of "losing" this righteousness through sinning. But remember, it's a gift.
...When the kindness and the love of God our Savior toward man appeared, not by works of righteousness which we have done, but according to His mercy He saved us, through the washing of regeneration and renewing of the Holy Spirit, whom He poured out on us abundantly through Jesus Christ our Savior, that having been justified by His grace we should become heirs according to the hope of eternal life. Titus 3:4-7"According to His mercy" He saved us, washed us, regenerated us and renewed us. It's ALL about His kindness, His mercy, His abundant gift of righteousness! If we're mired down with a sin consciousness, worried about every little (or big) sin, worried that we'll somehow cross God (when His cross has taken care of it ALL!), then we're missing the point. A sin consciousness won't cause you to walk according to the gift of righteousness! (Hello?!!).
TRUST what God has done for us, and we won't have to worry about whether or not we're messing up His work. Good news: His work supersedes ours! God has made you RIGHTEOUS!