It is written: “Wizards thou shalt not suffer to live” (Ex. 22:18); and: “In the morning I put to death all the wicked of the land” (Ps. 100:8). ….
Every part is directed to the whole, as imperfect to perfect, wherefore every part exists naturally for the sake of the whole. For this reason we see that if the health of the whole human body demands the excision of a member, because it became putrid or infectious to the other members, it would be both praiseworthy and healthful to have it cut away. Now every individual person is related to the entire society as a part to the whole. Therefore if a man be dangerous and infectious to the community, on account of some sin, it is praiseworthy and healthful that he be killed in order to safeguard the common good, since "a little leaven corrupteth the whole lump” (1 Cor. 5:6).
(Summa Theologiae, II, II, q. 64, art. 2).
The fact that the evil ones, as long as they live, can be corrected from their errors does not prohibit that they may be justly executed, for the danger which threatens from their way of life is greater and more certain than the good which may be expected from their improvement.
They also have at that critical point of death the opportunity to be converted to God through repentance. And if they are so obstinate that even at the point of death their heart does not draw back from malice, it is possible to make a quite probable judgment that they would never come away from evil.”
(Summa contra gentiles, Book III, chapter 146)