Shaykh al-Islām Ibn Taymiyyah [d. 728 AH] said: “There can be no doubt that having an intention for fasting is obligatory, for if one fasted without an intention, he could not expect to be rewarded. This is because reward only follows [the actions] we intend. Similarly, we will be rewarded for the [ḥarām] actions we choose to leave for Allāh. However, if it had not even occurred to an individual to actively and with pre-emptive thought, abandon an action, he would not be punished or rewarded. Just as if he intends to leave something for Allāh but engages in it due to forgetfulness; this forgetfulness does not lessen his reward [due to his intention]. Rather, he is deserving of reward for intending to leave that action, even if ultimately he forgetfully engaged in it.
Thus is fasting, whatever a person engages in [unintentionally] during the fast is not associated with him in actuality. Rather, this would be counted from among what Allāh has done with him without his intending it. Hence, the Prophet [ﷺ] said: ‘Whomsoever eats or drinks out of forgetfulness, let him complete his fast. For it is only Allāh that has fed him and provided him with drink.’ Here, the eating and drinking is associated with Allāh because he [the fasting person] did not intend or seek out [what was consumed]. Whatever is associated to Allāh is, therefore, not forbidden for His slave. The slave has only been forbidden to engage in actions for which he possess the volition to carry out. As for actions that do not fall under his free will, they are not included from among his actionable responsibilities. Thus, the actions of a forgetful person is comparable to the actions of a sleeping person, or one who has lost his mind, or is underage, and the likeness [of these categories]. This can be further clarified with the fact that a fasting person who has a wet dream does not break his fast, but if he was to intentionally masturbate he would break his fast. Similarly, if a [fasting person] vomits unintentionally he does not break his fast, but if he was to force himself to vomit intentionally with aforethought he would break his fast. So if the actions that were engaged in intentionally by a fasting person were comparable to that which is executed unintentionally, either action [intentional and unintentional] would be sufficient in nullifying the fast.”
Source: Majmūʿ al-Fatāwá 10: 474
Translated by: Riyāḍ al-Kanadī