I think baptism is part of God seeing us righteous. Not the fact we physically did something. That's where people misunderstand baptism and think it's salvation by works. Baptism puts us into the death of Christ. That requires letting go of self. And getting into Christ is getting into righteousness.
"IN" Jesus is righteousness.
1 Corinthians 1:30 KJV But of him are ye in Christ Jesus, who of God is made unto us wisdom, and righteousness, and sanctification, and redemption:
We're not IN Christ by our efforts when we get baptized into Him. It is OF GOD who does an operation of extracting us from Adam and putting us instead into Christ.
Colossians says the same.
Colossians 2:9-12 KJV For in him dwelleth all the fulness of the Godhead bodily. (10) And ye are complete in him, which is the head of all principality and power: (11) In whom also ye are circumcised with the circumcision made without hands, in putting off the body of the sins of the flesh by the circumcision of Christ: (12) Buried with him in baptism, wherein also ye are risen with him through the faith of the operation of God, who hath raised him from the dead.
Here we see placement IN CHRIST associated once again with baptism. And also the concept of God's work or operation is highlighted, not our own as if we can boast of being baptized. Anybody who boasts of baptism never grasped what it's about. Anybody who looks at it as a work is not seeing the aspect involved of putting us into Christ and His operation.
Jesus is my righteousness, not my good works. His death stands as our deaths, and anyone who also grasps that correctly enough to get saved by it understands baptism puts us into that death where self cannot work to save itself any more than the slaying of a man with all his good works makes that man great in himself in a prideful way.
Paul said he wanted to found of God by being IN CHRIST, which comes by baptism into His death, and not in his own righteousness. So, righteousness is intergrally linked to baptism if we see it puts us into His death.
Philippians 3:8-9 KJV Yea doubtless, and I count all things but loss for the excellency of the knowledge of Christ Jesus my Lord: for whom I have suffered the loss of all things, and do count them but dung, that I may win Christ, (9) And be found in him, not having mine own righteousness, which is of the law, but that which is through the faith of Christ, the righteousness which is of God by faith:
How do we get into Him?
Romans 6:3 KJV Know ye not, that so many of us as were baptized into Jesus Christ were baptized into his death?
We rise into newness of life which includes possessing HIS RIGHTEOUSNESS after we've been baptized into His death.