This is an excellent question with a surprising answer, or what may be surprising to some.
To clarify the question (since I think some may have misunderstood it) is not the faith/works debate but rather why James seems to think that Abraham's test experience demonstrates that Abraham "believed God, and it was imputed unto him for righteousness".
IE: How does it follow that Abraham's obedience fulfilled the imputation of faith as righteousness?
(Hopefully I understood that correctly).
The answer is, I believe, that according to James, Genesis 15:6 is speaking prophetically, not historically of Abraham's faith being counted to him as righteousness. If so, this upends a strongly held delusion (a "stronghold of the mind") that Abraham's justification was conceptual, not costly or dear.
This also dovetails with the concept of the "trial of faith":
[1Pe 1:7 KJV] (7) That the trial of your faith, being much more precious than of gold that perisheth, though it be tried with fire, might be found unto praise and honour and glory at the appearing of Jesus Christ:
[1Pe 4:12 KJV] (12) Beloved, think it not strange concerning the fiery trial which is to try you, as though some strange thing happened unto you:
We this expressed in the gospels:
[Mat 10:32-33 KJV] (32) Whosoever therefore shall confess me before men, him will I confess also before my Father which is in heaven. (33) But whosoever shall deny me before men, him will I also deny before my Father which is in heaven.
What confessing Christ before men meant in the first century was to surrender one's life into God's hands. If you failed to confess Christ to save your life you would forfeit your salvation.
It changes everything. "Sola Fide", to the degree that it means "Abraham's instant and permanent justification by an untested and unaccountable faith" is an evil brew.
[What a wowzer of a question!]
In the NT there is a palpable awareness of the soon return of Jesus to judge the quick and the dead, etc. The goal of each believer's life was to be prepared to meet Jesus whether he came morning, noon or night. The believers understand that Jesus was coming with their reward. That is, they saw faith as a race. Each believer has a race set before them. If they finish the race, they win the crown (which represents everlasting life). This is clearly how James views the deal:
[Jas 1:12 KJV] (12) Blessed is the man that endureth temptation: for when he is tried, he shall receive the crown of life, which the Lord hath promised to them that love him.
We see the same in Revelation:
[Rev 2:10 KJV] (10) Fear none of those things which thou shalt suffer: behold, the devil shall cast some of you into prison, that ye may be tried; and ye shall have tribulation ten days: be thou faithful unto death, and I will give thee a crown of life.