Islamic Ruling on Farting Inside the Mosque
It is disliked and may even be sinful to fart inside the mosque because it disturbs people and angels.
This fatwa explains the ruling using the hadith of Hazrat Jabir رضی اللہ عنہ. The Prophet صلی اللہ علیہ وسلم said that a person who eats onions or garlic should not come to the mosque, because angels are harmed by the same things that harm people. (Muslim 564)
Islamic scholars say that the mosque is the house of Allah, and angels are present in it. Anything that bothers people also bothers the angels. Farting inside the mosque causes discomfort to others, so scholars advise avoiding it.
Some scholars say that if a person can go outside but still chooses to fart inside the mosque, it can become haram. In Al Majmu 2/200, it is mentioned that farting in the mosque is not always forbidden, but avoiding it is better because it harms the angels. Other scholars say it is disliked, and if done without need, it may even become haram because the hadith warns against causing harm.
This is the Islamic ruling according to the given fatwa.