Okay, this is the epic struggle between Paul's
'justification by faith apart from works', and James'
'justification by works done in faith'. It's a difficult matter to reconcile, but easily explained when you understand that 'justified' has two distinct definitions. One definition is
'to be made righteous', and another definition is
'to be shown to be righteous'. This is easily confirmed here:
https://www.thefreedictionary.com/justify
Paul is using the word 'justified' in regard to
becoming righteous by receiving the righteousness that is from God through faith in God (Romans 3:22). James is using the word 'justified' in regard to
showing yourself to have the righteousness of faith through the evidence of your obedient works (James 2:18).
It's clear that the genuine believer must be justified by, both, faith and works. But not because works somehow make you righteous in God's sight, but because they are the obligatory and expected outcome of having received the righteousness of God by faith apart from works. In short, the person who can not demonstrate by his life that he has received the righteousness of God is showing the he does not really have the righteousness that is from God! And so a man must be justified by works and not faith alone (James 2:24), for what that actually means. It does not mean works somehow make a man righteous.
Faith does that all by itself. It means that you must have the works that show/prove that you have been made righteous through faith in God.