There are two issues:
1.) The way to become a character trait.
2.) The content of what we are becoming when we become that character trait.
The way to become a character trait is by believing that we ought to be someone who practices that trait and what we are becoming when we become that trait is someone who practices it. For example the way to become courageous is through faith that we ought to be courageous and what we are becoming when we become courageous is someone who practices courageousness. The same is true for any other character traise including becoming righteous. God's law is His instructions for how to practice righteousness, not for how to become righteous.
God practices holiness, righteousness, goodness, justice, mercifulness, faithfulness, love, joy, peace, patience, kindness, gentleness, self-control, and so forth, so the way to believe in God, in the character of who He is is by having faith that ought to be someone who practices the same traits and God's law is His instructions for how to practice those traits. Our goal is to be in God's image and to faithfully represent the nature of who He is. For example, when we do good works we are believe in God's goodness as being the guide for how we ought to live and are testifying about God's goodness, which is why our good works bring glory to Him (Matthew 5:16). Someone can look at the character of our works and see what we believe to be true about the character of God, which is why James 2:18 says that he would show his faith by his works. We are to trust with all of our heart in the revealed goodness of God to be the guide for how we ought live our lives and he will make our way straight rather than leaning on our own understanding by doing what is right in our own eyes.
So I agree that we do not become righteous as the result of having first obey God's law, but rather we become righteous through faith and what we are becoming when we become righteous through faith is someone who practices righteousness in obedience to God's law through that faith.