Then when he says but to him, he shows how the eternal reward is related to faith, saying, but to him who works not outward works, for example, because he does not have time to work, as in the case of one who dies immediately after baptism, yet believes in him who justifies the ungodly, namely, in God, of whom he says below: God is he who justifies (Rom 8:33), his faith is reputed, i.e., faith alone without outward works, to justice, so that in virtue of it he is called just and receives the reward of justice, just as if he had done the works of justice, as he says below: with the heart, we be...lieve unto justice (Rom 10:10), and this according to the purpose of the grace of God, i.e., accordingly as God proposes to save men gratuitously: to such as, according to his purpose, are called to be saints (Rom 8:28); he accomplishes all things according to the counsel of his will (Eph 1:11).
Another explanation refers those words to man's justification.
He says therefore, to him who works, i.e., if anyone be justified by works, the justice would be reckoned as a reward, not according to grace, but according to debt: and if by grace, it is not now by works; otherwise grace is no more grace (Rom 11:6). But to him who works not, so as to be justified by his works, yet believes in him who justifies the ungodly, his faith is reputed to justice, according to the purpose of the grace of God, not that he merits justice through faith, but because the believing itself is the first act of the justice God works in him. For from the fact that he believes in God justifying, he submits himself to his justification and thus receives its effect.
This is the literal explanation and accords with the intention of the Apostle, who lays special stress on the words, it was reputed to him as justice (Gen 15:6), a saying which is used when that which is lacking on someone's part is reckoned to him gratis, as if he had accomplished the whole.
That is why the Apostle says that such reckoning would have no place, if justice were from works, but only as it is from faith.
Source: Commentary on Romans