The gastroscope is a medical instrument that is inserted into the stomach via the mouth, and is used either to take a picture of the stomach or to take a sample for examination, or for other medical purposes, then after the procedure is complete, the instrument is removed via the mouth.
The scholars differed as to whether, if something reaches the stomach, it invalidates the fast in all cases, whether it is provides nourishment or not, or does it not invalidate the fast if it does not provide nourishment?
Three schools are of the view that the fast is broken by everything that enters the stomach: the Maalikis, the Shafi and the Hanbali. Based on that, this gastroscopy does invalidate the fast.
The Hanafis agreed with them that everything that reaches the stomach invalidates the fast, but they stipulated that it should remain in the stomach. Based on that, gastroscopy does not invalidate the fast, because it does not remain in the stomach, rather it is removed once the procedure is completed.
See: Tabyeen al-Haqaaiq by al-Zaylai (1/326); al-Majmoo (6/317); al-Sharh al-Kabeer (7/410); Sharh Muntaha al-Iraadaat (1/488); Bidaayah al-Mujtahid (2/153).
Sheikh al-Islam Ibn Taymiyah was of the view that the fast is not broken unless a nourishing substance reaches the stomach. He said: The more correct view is that the fast is not broken by swallowing something that does not provide nourishment, such as swallowing a pebble. End quote from Majmoo al-Fatawa (20/528). Based on this view, this gastroscopy does not invalidate the fast, and this view is more likely to be the correct one, because the text only indicates that eating and drinking spoil the fast. Allah says (interpretation of the meaning): “and eat and drink until the white thread (light) of dawn appears to you distinct from the black thread (darkness of night), then complete your fast till the nightfall [al-Baqarah 2:187].
The gastroscope is neither food nor drink, and is not akin to food or drink, because the body does not benefit from it and is not nourished by it. But, if any kind of greasy substance is put on the gastroscope to make it easier to insert it into the stomach, or some saline solution is introduced via the gastroscope to clean it and make it easier to take images, then the fasting person’s fast is invalidated when this substance reaches the stomach, because the body will absorb it and be nourished by it, so it is like food and drink.
Sheikh Ibn Uthaymeen said in al-Sharh al-Mumti (6/370, 371) – when explaining that everything that reaches the stomach invalidates the fast according to the madhhab of Imam Ahmad – : If a person has a gastroscope inserted and it reaches the stomach, then this breaks the fast [i.e., according to the Hanbali school]. But the correct view is that it does not break the fast unless there is any grease or the like on the gastroscope that may reach the stomach via the gastroscope. In that case it breaks the fast, and it is not permissible to use it during an obligatory fast except in case of necessity. End quote.
In a statement of the Islamic Fiqh Council it says: "The following things are not regarded as breaking the fast: … gastroscope if it is not accompanied by introduction of fluids (solutions) or any other substance." Majallat al-Majma (10/2/453-455).
To sum up: If the gastroscope is inserted into the stomach without introducing any other substances, then it does not break the fast, but if some greasy substance or anything else is introduced with it then it does invalidate the fast.