From the Summa Theologica.
Whether fasting is an act of virtue?
Objection 1. It would seem that fasting is not an act of virtue. For every act of virtue is acceptable to God. But fasting is not always acceptable to God, according to Isaiah 58:3, "Why have we fasted and Thou hast not regarded?" Therefore fasting is not an act of virtue.
Objection 2. Further, no act of virtue forsakes the mean of virtue. Now fasting forsakes the mean of virtue, which in the virtue of abstinence takes account of the necessity of supplying the needs of nature, whereas by fasting something is retrenched therefrom: else those who do not fast would not have the virtue of abstinence. Therefore fasting is not an act of virtue.
Objection 3. Further, that which is competent to all, both good and evil, is not an act of virtue. Now such is fasting, since every one is fasting before eating. Therefore fasting is not an act of virtue.
On the contrary, It is reckoned together with other virtuous acts (2 Corinthians 6:5-6) where the Apostle says: "In fasting, in knowledge, in chastity, etc. [Vulgate: 'in chastity, in knowledge']."
I answer that, An act is virtuous through being directed by reason to some virtuous [honestum] [Cf. 145, 1] good. Now this is consistent with fasting, because fasting is practiced for a threefold purpose. First, in order to bridle the lusts of the flesh, wherefore the Apostle says (2 Corinthians 6:5-6): "In fasting, in chastity," since fasting is the guardian of chastity. For, according to Jerome [Contra Jov. ii.] "Venus is cold when Ceres and Bacchus are not there," that is to say, lust is cooled by abstinence in meat and drink. Secondly, we have recourse to fasting in order that the mind may arise more freely to the contemplation of heavenly things: hence it is related (Daniel 10) of Daniel that he received a revelation from God after fasting for three weeks. Thirdly, in order to satisfy for sins: wherefore it is written (Joel 2:12): "Be converted to Me with all your heart, in fasting and in weeping and in mourning." The same is declared by Augustine in a sermon (De orat. et Jejun. [Serm. lxxii (ccxxx, de Tempore)]): "Fasting cleanses the soul, raises the mind, subjects one's flesh to the spirit, renders the heart contrite and humble, scatters the clouds of concupiscence, quenches the fire of lust, kindles the true light of chastity."
Reply to Objection 1. An act that is virtuous generically may be rendered vicious by its connection with certain circumstances. Hence the text goes on to say: "Behold in the day of your fast your own will is founded," and a little further on (Isaiah 58:4): "You fast for debates and strife and strike with the fist wickedly." These words are expounded by Gregory (Pastor. iii, 19) as follows: "The will indicates joy and the fist anger. On vain then is the flesh restrained if the mind allowed to drift to inordinate movements be wrecked by vice." And Augustine says (in the same sermon) that "fasting loves not many words, deems wealth superfluous, scorns pride, commends humility, helps man to perceive what is frail and paltry."
Reply to Objection 2. The mean of virtue is measured not according to quantity but according to right reason, as stated in Ethic. ii, 6. Now reason judges it expedient, on account of some special motive, for a man to take less food than would be becoming to him under ordinary circumstances, for instance in order to avoid sickness, or in order to perform certain bodily works with greater ease: and much more does reason direct this to the avoidance of spiritual evils and the pursuit of spiritual goods. Yet reason does not retrench so much from one's food as to refuse nature its necessary support: thus Jerome says:* "It matters not whether thou art a long or a short time in destroying thyself, since to afflict the body immoderately, whether by excessive lack of nourishment, or by eating or sleeping too little, is to offer a sacrifice of stolen goods." [The quotation is from the Corpus of Canon Law (Cap. Non mediocriter, De Consecrationibus, dist. 5). Gratian there ascribes the quotation to St. Jerome, but it is not to be found in the saint's works.] In like manner right reason does not retrench so much from a man's food as to render him incapable of fulfilling his duty. Hence Jerome says (in the same reference) "Rational man forfeits his dignity, if he sets fasting before chastity, or night-watchings before the well-being of his senses."
Reply to Objection 3. The fasting of nature, in respect of which a man is said to be fasting until he partakes of food, consists in a pure negation, wherefore it cannot be reckoned a virtuous act. Such is only the fasting of one who abstains in some measure from food for a reasonable purpose. Hence the former is called natural fasting [jejunium jejunii] [Literally the 'fast of fasting']: while the latter is called the faster's fast, because he fasts for a purpose.