The hadeeth that is reported from the Prophet (salallāhu ‘alaihi wasallam) negating contagious diseases is related to what the people of pre-Islamic ignorance used to believe―that a contagious disease itself brings about an effect (and transmits itself from person to person).
As for the Prophet’s (salallāhu ‘alaihi wasallam) prohibition of entering a land which is afflicted by a contagious disease, then that is to act upon a means of protection [from harm]. (See, Al-Jāmi’ fī Fiqhil-‘Allāmah Ibn Bāz, p. 1179-80)
As for leaving a land which has been afflicted by a contagious disease, then Al-Hāfidh Ibn Hajr (died 852H, rahimahullāh) cited the speech of At-Tahāwi who brought a benefit in saying that the Prophet’s (salallāhu ‘alaihi wasallam) prohibition of leaving a place afflicted by a contagious disease is so that it is not said by the people: “He left, so he was saved.” Then Ibn Hajr (rahimahullāh) stated:
“There are three scenarios here:
1. The person who leaves an afflicted area purely to flee from it―then he has fallen into that which is prohibited, without any doubt.
2. The one who leaves an afflicted area purely for a need or purpose and not with the intent to flee from the contagious disease at all―this person does not fall into the prohibition.
3. The one for whom a need arises, so he wants to leave to take care of his need, and he combines with that an intent to find relief from staying in the land where there is a contagious disease―and this is a point of dispute… and there has been reported from the Salaf some differing concerning it.” (Fathul-Bāri, 10/214)
Bukhāree (5756) and Muslim (2224) report from Anas Ibn Mālik (radiyallāhu ‘anhu) that Allah’s Messenger (salallāhu ‘alaihi wasallam) said:
لاَ عَدْوَى وَلاَ طِيَرَةَ وَيُعْجِبُنِي الْفَأْلُ الصَّالِحُ وَالْفَأْلُ الصَّالِحُ الْكَلِمَةُ الْحَسَنَةُ
“There are no contagious diseases [except as Allah wills it] and no evil omen, and I am pleased by a good omen―and a good omen is a good word.”
Shaikh Ibn Bāz (rahimahullāh) stated: Its meaning is to falsify the belief of the people of jāhiliyyah (pre-Islamic ignorance) who held that diseases spread by themselves. So the Prophet (salallāhu ‘alaihi wasallam) informed them that this was falsehood.
The One who controls every part of creation is Allah alone. Some of those who were present with the Prophet (salallāhu ‘alaihi wasallam) said: “O Allah’s Messenger, what about the camels which, when in the desert sand look like deers, but when a mangy camel mixes with them they all get infected with mange?” So the Prophet (salallāhu ‘alaihi wasallam) replied,
فَمَنْ أَعْدَى الأَوَّلَ
“Then who brought the [mangy] disease to the first camel?” Meaning that the One who sent the mange disease to the first camel is the same One who sent it to the others. Then he explained to the Companions that mixing with those afflicted is a means of transferring the disease from a sick person to a healthy person by the permission of Allah. For this reason he (salallāhu ‘alaihi wasallam) said:
لاَ يُورِدُ الْمُمْرِضُ عَلَى الْمُصِحِّ
“A man with sick camels should not let them graze or drink alongside healthy ones.” (Ibn Mājah, no. 3541) or in the context reported by Bukhāri (5771) and Muslim, he said: “The sick one should not be brought to the healthy one.”
This means that it is prohibited to bring the sick, diseased or mangy camel near a healthy camel because this type of mixing may be a cause of transferring the disease from the sick one to the healthy one. For this reason, he (salallāhu ‘alaihi wasallam) said:
وَفِرَّ مِنَ الْمَجْذُومِ كَمَا تَفِرُّ مِنَ الأَسَدِ
“One should flee from the leper as one flees from a lion.” (Bukhari, no. 5707) That is because mixing with the afflicted may be a means of transmitting the disease from one person to another―and it has been established from the Prophet (salallāhu ‘alaihi wasallam) that the transmission of leprosy (or other contagious diseases) from a sick person to a healthy person only occurs by the Will of Allah and His Permission―and it is not something that will definitely happen.
So, in conclusion, the various narrations in this subject prove that there is no contagious disease as was believed by the people in the times of pre-Islamic ignorance who believed (and as many ignorant people believe today) that diseases spread by themselves naturally. Rather, the affair is in the Hands of Allah (the Most Perfect)―if He (the Most High) wills, the disease will transmit from the sick person to the healthy person, and if He (the Mighty and Majestic) wills, it will not transmit.
However, the Muslims are commanded to take the means that will benefit them, and keep away from that which may harm them.
Ref: من ضمن الأسئلة الموجهة لسماحته من مجلة الدعوة، وقد أجاب عنه سماحته بتاريخ 24/12/1418هـ