Romans 4:5
However, to the one who does not work but trusts God who justifies the ungodly, their faith is credited as righteousness.
But however it contradicts with the portion of James that says works are important.
St. Paul here is explaining how a man that is not yet in a covenant relation with GOD, neither circumcised nor baptised, CAN be attracted by the love of GOD (Grace) and become a member of the family of Christ, The Church HE founded.
And to do this he uses Abraham who we read in the previous verse that “Abram believed God, and it was reputed to him unto justice.” notice St. Paul uses the original name of Abraham before GOD changed his name. When Abram “believed” he was not circumcised yet. However GOD accepted him into HIS family. ONLY because he believed.
NOW very important to note also that none of our works count for anything unless we are members of the family. For Jesus said that apart from HIM we cannot do anything.
Because Jesus is GOD and HE is outside time HIS redemption action is valid for all humans that ever lived since Adam, hence Abram works were counted to his credit even though he never met Jesus.
What this mean is that our works merit a reward when GRACE which is freely infused into us make those works acceptable to GOD.
And as you correctly noted it is a requirement for one who has faith and Grace to do good works.
For a faith without works is a dead faith.
And this is the reason why, the Catholic Church teaches, that even an unbaptised person who never knew Jesus through no fault of his/her own can be saved. If he/she followed his/her conscience (the law written in the heart of every human.
Hope this helps you.
…