Answered by the Egyptian House of Fatwa
What is the ruling of the Shari’ah for individuals with infectious diseases such as influenza who frequent mosques to pray and spread the disease like wild fire among those praying in the mosques?
Islam takes into consideration the life and health of Muslims and forbids people from killing each other. Allah the Almighty says: Do not kill each other, for God is merciful to you [4:29], … Do not contribute to your destruction with your own hands, but do good, for God loves those who do good [2:195]. The Messenger of Allah said: “Do not cause harm and do not reciprocate harm” [Ibn Majah].
One of the established legal maxims is to ‘undertake the lesser harm to ward off the greater’. Therefore, if a Muslim comes down with an infectious disease, he must avoid mixing with others so as not to spread it among them. He must pray in his home until Allah, the Almighty, cures him; there is no harm in this because the Messenger of Allah said: “If a land is stricken by plague, do not enter it; and if it is stricken by plague while you are in it, do not depart from it” [Ahmed]. This is what is known today as quarantine.
If eating food with offensive smells is a reason for abandoning congregational prayers to prevent harming others, then abandoning congregational prayers for fear of transmitting infectious diseases and harming those who are praying comes first.
Allah, the Almighty, knows best.