Muslim scholars maintained that one of the main objectives of the Sharia is protecting people’s life and maintaining their health. Human life is highly appreciated in Islam that matters relating to health take precedence over acts of worship.
Prophet Muhammad (peace and Blessings be upon him) said, “There should be neither harm nor reciprocation of harm.” (IbnMajah) This hadith illustrates that a Muslim should not be a source of harm for others in any way.
Responding to this question, Sheikh `AtiyyahSaqr, former head of Al-Azhar Fatwa Committee, stated,
If the disease is confirmed and the infection is likely to occur, then the situation suggests cancellation or delay of the obligation of Hajj for the infected people until they recover. A fiqhi (juristic) rule states that averting (the causes of) harm has precedence over bringing about benefits (Dar’ ul mafasid muqaddamun ‘ala Jalbil Masalih). The benefits of performing Hajj is go to the one who performs its, while the harm is the share of others in case of those with infectious diseases.
Thus, I believe that if such people take the risk of going to Hajj while their Hajj can be cancelled because of the infection, then this act is forbidden, either by way of Karahah (religious reprehension) or Tahrim (prohibition), depending on the degree of infection.
There are many hadiths that warn against exposing oneself to infection or causing it or inflicting it to others. Imam Muslim reported that there was a leper among the delegation of Thaqif, who came to pledge allegiance to the Prophet (peace and blessings be upon him). Upon knowing that, Allah’s Prophet sent him the following message: “We have accepted your allegiance, so you may go.” Also, Imam Al-Bukhari reported that the Prophet said, “Run away from the leper as you run away from a lion.”
Based on this rule (i.e., the prohibition of inflicting or reciprocating harm), Islam forbids the carrier of the disease from mixing with healthy people because that can transmit the infection to them, either directly or indirectly. Islam also forbids spitting in the streets and other public places. It forbids urinating and defecating in water sources and any places frequented by people. It orders Muslims to kill the insects, vermin, and other creatures that can harm people, even during ihram (state of ritual consecration).
Imam Malik reported that `Umaribn Al-Khattab (may Allah be pleased with him) saw a leprous woman performing Tawaf (circumambulation of the Ka`bah) among people. He said to her, “O maidservant of Allah! Do not harm others. Why do you not stay home?” The woman obeyed him and stayed home. When `Umar died, a man visited her and said, “The one who forbade you from making Tawaf has passed away. You may now go and perform Tawaf.” She replied, “Having obeyed him in his life, I shall not and disobey him after his death.”