From his commentary on the book of Romans (c.8 l.6 §696), on the claim that all things work together unto good for the saints:
To realize this we should consider that whatever happens in the world, even if it be evil, accrues to the good of the universe; because, as Augustine says in Enchiridion: God is so good that he would permit no evil, unless he were powerful enough to draw some good out of any evil.[Saint Thomas Aquinas, Commentary on the Letter of Saint Paul to the Romans, Larcher, OP, tr., Mortensen and Alarcón, eds. The Aquinas Institute for the Study of Sacred Doctrine (Lander, WY: 2012): 231-232.]
However, the evil does not always accrue to the good of that in which it is. Thus, the death of one animal accrues to the good of the universe, inasmuch as by the destruction of one thing something else begins to be, although it does not accrue to the good of that which ceases to be; because the good of the universe is willed by God according to itself and to this good all the parts of the universe are ordained.
The same seems to apply to the relationship of the noblest parts to the other parts, because the evil affecting the other part is ordained to the good of the noblest parts. but whatever happens to the noblest parts is ordained only to their good, because his care for them is for their sake, whereas his care for the others is for the sake of the noblest: as a physician allows a malady in the foot that he might cure the head.
But the most excellent parts of the universe are God's saints, to each of whom applies what is said in Matthew: he will set him over all his goods (Matt 25:23). Therefore, whatever happens to them or to other things, it all accrues to the benefit of the former. This verifies the statement in Proverbs: the fool will be servant to the wise (Prov 11:20), namely, because even the evil of sinners accrues to the good of the just. Hence, God is said to exercise a special care over the just: the eyes of the Lord are toward the righteous (Ps 34:15), inasmuch as he takes care fo them in such a way as to permit no evil to affect them without converting it to their good.
This is obvious in regard to the penal evils which they suffer; hence it says in the Gloss that in their weakness humility is exercised, in affliction patience, in contradictions wisdom, and in hatred good will. Hence it says in 1 Peter: if you suffer for justice's sake, you will be blessed (1 Pet 3:14).