From Summa Theologiæ II-II 147 and In IV Sent. d. 15, q. 3, a. 1, qa. 2
Is fasting a virtue?
1. It seems that fasting is not a virtue, since every, both good and bad persons, are fasting before they eat. But virtue is done only by good persons. Therefore fasting is not a virtue.
2. Further, fasting means not only abstaining from superfluity of food, but also from what is necessary. But he who withholds from himself necessary food, gives himself an occasion of death; for there is no difference, as Jerome says, whether you kill yourself in a long or a short time. Therefore since no one is permitted to kill himself, it seems to no way is permitted to fast, and so fasting is not virtuous.
I respond, an action is virtuous due to its being directed by reason to a noble good. And this is true of fasting. For we fast for three purposes: (1) to restrain the desires of the flesh; (2) to raise the mind to contemplate sublime things; (3) to make satisfaction for our sins. These are good and noble things, and so fasting is virtuous.
To the first objection it should be said that the “fast of nature”, which everyone is said to be doing before they eat, consists simply in a negation (i.e., that someone hasn’t eaten yet, and isn’t eating now). So this fasting cannot be called a virtuous act, but only that fasting by which a person somehow abstains from food for a reasonable purpose.
To the second objection it should be said that food can be necessary in two ways. First, for preserving life. And food necessary in this way one may not abstain from by fasting, just as one may not kill oneself. But this necessary is very little, since nature is content with small amounts. In another way food is necessary for preserving the strength of the body. And this may be understood in two ways: (1) in one way, as sufficient strength with respect to the things that one must do because of one’s position, or because of the company of those with whom one lives; and we may also not abstain from food necessary in this way, since this would be to offer a fast of theft (from those to whom one is obliged), if someone on account of fasting were hindered from doing to the works to which he would otherwise be obliged. Hence Jerome says, “he who immoderately afflicts his body either by eating too little food, or by taking too little sleep, offers a sacrifice of theft.” Also if a man’s abstains so much from food that he is hindered from more useful deeds, even if he is not bound to do them, his fasting is injudicious, even if not forbidden. Hence Jerome says, “rational man loses dignity, if he prefers fasting to charity, or vigils to integrity of the senses.” (2) Strength of body may be taken in the sense of the body’s being disposed as well as possible; and since the flesh in its vigor is only with difficulty subjected to the spirit, it may be praiseworthy to withhold from the body what is necessary for strength in this sense, even if one could licitly take it. And withholding this nourishment does not significantly (multum) hasten death, since the human body more frequently becomes deathly ill due to superfluity than due to a deficiency. Hence Galen says that abstinence is the supreme medicine. It is also a matter of experience that those who abstain from food frequently live longer; hence this abstaining from food cannot be called an occasion of death, since it may do either: i.e., prolong or shorten life. But abstaining from what is unnecessary in either of these senses mentioned above, is obligatory by the virtue of temperance.