Mary was righteous because of the grace of Jesus under the new covenant which made heaven possible.
For it is by grace that we are made righteous and not by the law.
Galatians 2:21 KJV I do not frustrate the grace of God: for if righteousness come by the law, then Christ is dead in vain.
We speak of two different conditions of righteousness, one the Judaic and one Christian.
Mary, being full of grace, was made completely righteous by her Son, Jesus.
Before there was the Teachings of Moses When YHvH calls someone Righteous, Mary was a sinner just like every created being I'm afraid you are viewing the WORD
shalom b'SHEM Yah'shua HaMashiach
through the lens of replacementarianism.
there were those who were called righteous :
See: Gen. 6:9; 7:1; 18:23ff, 28; 38:26; Gen. 15:6; 18:19;
does He change His mind as to which covenant ?
in need of salvation by YHvH.
Catholic doctrine does not teach other than Mary a sinner in need of a Savior. The difference is in when she received the grace of Jesus.
I admit to having never heard the word replacmentarianism which doesn’t seem to be an actual word but I am guessing is one used by some to express a certain understanding of other beliefs.
This is also a guess, that it seems in the context in which you are using it, it means the belief that the Christian church has replaced the Jewish faith?
I do not think that is what I am espousing in regards to this discussion.
Joseph did not live before Moses and like all the Jews of his time, was under the law as given by God to Moses. When Joseph is spoken of as a righteous man, it is in regards to the law of the time, not as one under the new covenant which imparts righteousness to us through grace and not the law.
One cannot view each historical and pivotal person in the Bible through the same lens, as God has given them each a unique role.