Praise be to Allah.
If the fasting person forgets that he is fasting, then he eats or drinks something, his fast is still valid, and he does not have to make it up, because of the report narrated by al-Bukhaari (6669) and Muslim (1155) from Abu Hurayrah (may Allah be pleased with him), who said: The Prophet (blessings and peace of Allah be upon him) said: “Whoever forgets that he is fasting and eats or drinks something, let him complete his fast, for it is Allah Who fed him and gave him to drink.”
See also the answer to question no. 50041.
This hadith refers to anyone who eats or drinks because he forgot he was fasting, whether he ate a little or a great deal.
Some of the Shaafa‘is excluded from that the one who eats or drinks a great deal, and said that his fast is not valid. They gave as a reason for that the fact that it is rare to forget and eat a great deal.
See: al-Mawsoo‘ah al-Fiqhiyyah al-Kuwaitiyyah (40/280).
The more correct view is that his fast is valid, because so long as he forgot when he ate or drank, then he is included in this concession and favour from Allah, whether he ate a lot or a little. Hence an-Nawawi (may Allah have mercy on him) regarded as correct the view that he has not broken the fast.
An-Nawawi (may Allah have mercy on him) said: If he eats because he forgot that he was fasting, then if he ate a little, he definitely did not break his fast; if he ate a lot, then there are two points of view, just as there are two points of view concerning one who speaks a great deal whilst praying because he forgot.
I say: The more correct view in this case is that he has not broken his fast. And Allah knows best.
End quote from Rawdat at-Taalibeen (2/363).
So long as the Muslim intended to fast, if he then eats something because he forgot he was fasting, then his fast is still valid.
The generosity and grace of Allah are immense and know no bounds, may He be glorified and exalted.
But the excuse and the validity of the fast only apply in the case of one who actually did forget, not of one who is toying with the matter of worship. This is a matter that is between the individual and his Lord, from Whom nothing can be hidden.
And Allah knows best.