Derech Hashem, Part 4, Ch. 2 – 48
The second condition for bringing down this supreme blessing through Torah learning is a person’s good deeds. If a person does many good deeds he will be a proper receptacle for this blessing, but if he sullies himself with sins he becomes distanced from his Creator, and to him the verse applies, ‘and to the evil person G-d said, to what end do you speak of my rules?’.
But nevertheless, our Sages divulged a tremendous secret, that if evil people would indeed learn Torah, they would eventually be affected for the good. Since Torah is inherently holy, it is inevitable that it would not have some effect on the person occasionally, and over time this will have a strong effect on him until he changes for the better.
Our Sages said, ‘If only they would forsake me and not my Torah, for the light within will bring them back’. However, this is referring to those who learn for their own pleasure, or to demonstrate their acumen, as long as they treat it no less than other wisdoms, not to those who intentionally pervert it, or those who make light of it.