I believe that Romans 4:4-5 does not deny what Paul otherwise affirms in Romans 2 - that people are ultimately justified by their "good works".
No. Don't misunderstand. Paul is saying that you can only be declared righteous by the law
if you can keep the law--all of it. Something he uses scripture itself to show
no one can do. So even though it's true that you can be declared righteous by the law, it's a moot point. No one can keep the law. He's not teaching us that ultimately a person is made righteous (justified) by the law.
This is the necessary foundation to understand and accept his 'righteousness (by faith) apart from works' teaching (Romans 4:6). It's impossible for a person to receive something they are convinced they don't need. In this case, those who are confident of the righteousness of their own righteous work to obtain a declaration of righteousness will not, and can not, place their trust in God's free gift of righteousness. It's a free gift because it's not given in exchange for successful performance of righteous behavior, but is a righteousness given
'apart from' the condition of performing righteous work. It's a righteousness given when one accepts,
by faith, God's forgiveness for having broken the law--their unrighteousness being removed through that forgiveness. Even the faith to receive that forgiveness is itself a free gift offered
without the condition of meritorious work.
James then teaches us that it is the person who upholds the law who shows they have this righteousness by faith (the
faith, not work, that saves), their work being the evidence of that righteousness, not the procurer of it. And that is where 'works gospel' teaching goes wrong. They somehow use James 2 to argue that a man is
made righteous by what he does. If that really is what James is arguing then,
from the context of the law he is speaking in, we have no choice but to say he is saying a person IS declared righteous by works of the law in exact contradiction to what Paul teaches in the same Bible. That makes for a very serious contradiction in our Bibles. Are works gospel proponents really ready to go on record as supporting that? I doubt it.
Instead, the "worker" in Romans 4 is a metaphor. I am prepared to defend the following position: In Romans 4:4-5, Paul is not denying justification by good works, he is critiquing the specifically Jewish belief that God "owes" justification to the Jews simply because of their being born into a community that performs the works of the Law of Moses.
We know this matter of the Jews placing misguided trust in their Jewishness is true. But the truth of 'righteousness (by faith) apart from works' is applicable to
all people who think they are ultimately declared righteous (made righteous in the sight of God) by the performance of righteous work.
The message is clear. Salvation is by the unmerited favor (grace) of God given to us through the giving of the faith to place our trust in the forgiveness of Christ for the removal of unrigheousness. Unrigheousness can not be removed by righteous work.
That is impossible for a mortal man to do. The standard that must be kept to do that is the law (assuming they haven't already committed an unforgivable offense), and as Paul says NO ONE has, or can, keep the whole law. That's why salvation must be by the grace of forgiveness,
not by the merit of doing righteous things--any righteous thing.