Question Four of Chapter Five of the Third Decade
Why God permits human beings to be tempted by demons
It is asked why God permits human beings to be waylaid by demons.
To this it is answered thus. Since divine providence has ordained evils toward good and procures the good of inferior beings through superior ones, and since the angels themselves are intermediaries between God and human beings, the good of human beings is procured through angels. This is done in two ways.
In one way, directly, insofar as a human being is led back toward good and withdrawn from evil; and this is done through good angels.
In another way, indirectly, when someone is withdrawn from evil and advanced toward good through an attack by a contrary. Evil angels assigned to human beings for their exercise have the charge of effecting this procurement, with God permitting it.
These things are from Thomas in the questions concerning demons and in the First Part, question 115.
Addition
God therefore permits human beings to be pursued and attacked so that those who love him may be made manifest and those devoted to pleasures may be rejected. For if no adversary opposed them, the noble soldiers of the king would not be proved.