The passage says this: What then shall we say was gained by Abraham, our forefather according to the flesh? For if Abraham was justified by works, he has something to boast about, but not before God. For what does the Scripture say? “Abraham believed God, and it was counted to him as righteousness.” … We say that faith was counted to Abraham as righteousness. How then was it counted to him? Was it before or after he had been circumcised? It was not after, but before he was circumcised. He received the sign of circumcision as a seal of the righteousness that he had by faith while he was still uncircumcised. The purpose was to make him the father of all who believe without being circumcised, so that righteousness would be counted to them as well, and to make him the father of the circumcised who are not merely circumcised but who also walk in the footsteps of the faith that our father Abraham had before he was circumcised.
What does the comment “counted to him as righteousness” mean? James 2.21-24 explains that the comment was God’s prophecy that in future Abraham would be made righteous (i.e. justified), and the prophecy was fulfilled after he had offered Isaac: Was not Abraham our father justified by works when he offered up his son Isaac on the altar? You see that faith was active along with his works, and faith was completed by his works; and the Scripture was fulfilled that says, “Abraham believed God, and it was counted to him as righteousness”—and he was called a friend of God. You see that a person is justified by works and not by faith alone. Righteousness is like a robe: I will greatly rejoice in the Lord; my soul shall exult in my God, for he has clothed me with the garments of salvation; he has covered me with the robe of righteousness, as a bridegroom decks himself like a priest with a beautiful headdress, and as a bride adorns herself with her jewels.[1] On account of his faith in God’s promise that he would have offspring, God awarded Abraham righteousness in Genesis 15. After Abraham had offered Isaac in Genesis 22, God put on Abraham the righteousness that he had earlier awarded: “By myself I have sworn, declares YHWH, because you have done this and have not withheld your son, your only son,I will surely bless you…” The word “bless” in this context means justify. God’s blessing of the seventh day made it holy: So God blessed the seventh day and made it holy…
The same applies to a believer today. On account of his faith in Jesus, God adjudges that he should be forgiven, and God chooses to forgive him at his baptism. Hence, Galatians 3.24-27 says that at baptism we put on Christ who is our righteousness: So then, the law was our guardian until Christ came, in order that we might be justified by faith. But now that faith has come, we are no longer under a guardian,for in Christ Jesus you are all sons of God, through faith. For as many of you as were baptized into Christ have put on Christ.
[1] Is 61.10.