Eid prayer in the mosque due to an excuse
It is narrated from Abu Hurayrah (may Allah be pleased with him):
انهم أصابهم مطر فى يوم عيد فصلى بهم النبى صلى الله عليه وسلم صلاة العيد فى المسجد
“On the occasion of an Eid, rain overtook the people, so the Prophet ﷺ led them in the Eid prayer in the mosque.”
Although this hadith is weak, a similar narration is also found from Umar (may Allah be pleased with him) as mawquf (a statement of a Companion), that if it rains, the Eid prayer may be performed in the mosque.
The permissibility is also indicated by this principle:
الضرورات تبيح الـمـخـطـورات
“Necessities make forbidden things permissible.”
◈ The scholars have differed on this issue: whether it is better to pray the Eid prayer in a spacious, wide mosque or to go out beyond the populated area to pray it.
(Shafi’i, may Allah have mercy on him) If the mosque of the area is itself spacious and wide, then praying in the mosque is better, because the main objective is the gathering of men and women, and that can take place in the mosque itself, so there is no need to go outside.
(Malik, may Allah have mercy on him) Going out beyond the populated area is better, because the Prophet ﷺ maintained this consistently, and Ali (may Allah be pleased with him) said regarding the Eid prayer outside the populated area: لولا أنه سنة الصليت فى المسجد “If this act (that is, going out beyond the populated area to perform the Eid prayer) were not a sunnah, I would pray in the mosque.”
(The preponderant view) The position of Imam Malik (may Allah have mercy on him) is the preponderant one.