Your question was “how do Torah works affect justification”? The short answer is they don’t; for salvation is solely by grace and faith and not by the works of the law for you quoted an appropriate verse:
Romans 3:20 (NKJV):
Therefore by the deeds of the law no flesh will be justified in His
sight, for by the law is the knowledge of sin.
You also referenced Galatian 2:18:
Galatians 2:18-21 (NKJV):
18 For if I build again those things which I destroyed, I make myself
a transgressor. 19 For I through the law died to the law that I might
live to God. 20 I have been crucified with Christ; it is no longer I
who live, but Christ lives in me; and the life which I now live in the
flesh I live by faith in the Son of God, who loved me and gave Himself
for me. 21 I do not set aside the grace of God; for if righteousness
comes through the law, then Christ died [j]in vain.”
Here Paul states that when a person accepts Christ’s sacrifice on the cross by faith as payment for their sin, that person then becomes dead to the law or better said, the law becomes dead to that person. Why, because Christ’s righteousness has been given to that person and thereby that person has been credited with fulfilling the whole Law of Moses. Hence, the law cannot accuse that person anymore since he/she has already fulfilled all its requirements through Christ.
If however, that person should leave Christ (or add anything to the finished work of Christ), Paul says in Galatians 2:18, that person would be in a sense rebuilding the foundation of the law where the person would be again responsible for their own righteousness or better said, that person would be again responsible to fulfill the entire law solely by their own works. That’s why Paul says if I “rebuild the things which I destroyed” (through faith in Christ I destroyed the requirement to fulfill the law myself) I then make myself a transgressor; I make myself again responsible for my own sin