It was to show his righteousness at the present time, so that he might be just and the justifier of the one who has faith in Jesus.
One of the most important aspects of our salvation is understanding fully what God has done in us through Christs’ sacrifice for us. Our enemy works at deceiving us in these areas so that he can take advantage of us. We need to understand the redemptive work that God has already fulfilled in us when we were born again. One of those key areas is the work of justification.
Justification means to be declared righteous, and therefore approved by God. This gift of righteousness is what gives us the right to what we have available as a child of God. If the devil can convince you that you are not right with God, he can hinder your faith in receiving what you have a right to. God demonstrated His righteousness (right standing with Him) through justification, which we have received through faith in Christ Jesus. You don’t work to get right with God, once you are born again you are right with God.
1 John 1:9 If we confess our sins, he is faithful and just to forgive us our sins and to cleanse us from all unrighteousness.
As a believer in Christ when we sin, we need to immediately confess our sin and turn to God. When we do God forgives us of our sin and He cleanses is from the sense of unrighteousness. You don’t lose your righteousness for if you did you would no longer be born again. But you lose your sense of righteousness knowing you sinned. Remember as a believer you have been justified, declared righteous, and if you sin, immediately confess your sin and turn to God knowing you have been justified through your faith in Jesus Christ.