Assalamualaikum ustaz. What is the ruling of leaving a place where there is an epidemic to another state to save ourselves from the disease?
Waalaikumussalam wrt. wbt.,
Alhamdulillah, praise and gratitude to Allah SWT for His countless blessings for us all. Praise and salutations to our beloved Prophet Muhammad PBUH, his family, companions, and all those who follow his footsteps until the Final day.
Generally, in facing any type of infectious disease, epidemic or other diseases, Islam first emphasizes preventive measures. Among the evidences that explain this matter is a hadith narrated by Sa’d Ibn Abi Waqas RA, he said Rasullullah PBUH said:
إِذَا سَمِعْتُمْ بِالطَّاعُونِ بِأَرْضٍ فَلاَ تَدْخُلُوهَا، وَإِذَا وَقَعَ بِأَرْضٍ وَأَنْتُمْ بِهَا فَلاَ تَخْرُجُوا مِنْهَا
“If you get wind of the outbreak of plague in a land, do not enter it; and if it breaks out in a land in which you are, do not leave it.” 
In this issue, there is also a hadith that mentioned the commandment of the Prophet PBUH to distance oneself from a leper because leprosy is a type of infectious disease. This is narrated by Abu Hurairah RA, he said, Rasullullah PBUH said:
وَفِرَّ مِنَ الْمَجْذُومِ كَمَا تَفِرُّ مِنَ الأَسَدِ
“And one should run away from the leper as one runs away from a lion.” 
Hadith scholars when commenting on this hadith presented several opinions which we’ll share as the following:
First: Some scholars deny the above hadith with the reasoning that it contradicts the action of Rasullullah PBUH. They said Rasullullah PBUH once ate with a leper and sit with him. The same is done by the companions of the Prophet PBUH. Among the arguments presented is a narration from Abd al-Rahman bin al-Qasim from his father who said:
أن وفد ثقيف أتوا أبا بكر الصديق فأتى بطعام فدعاهم فتنحى رجل، فقال مالك؟ قال مجذوم فدعاه وأكل معه
“A group of visitors from the people of Tsaqif came to meet Abu Bakr al-Siddiq. Then Abu Bakr serves them food and ask them to eat with him. A man stayed far away from them, Abu Bakr then asked: “What is wrong?” He replied: “I’m a leper”. Then, Abu Bakr called the man to eat with him.”
They also argued with a hadith narrated from Jabir bin Abdillah RA, he said:
أَنَّ رَسُولَ اللَّهِ ـ صلى الله عليه وسلم ـ أَخَذَ بِيَدِ رَجُلٍ مَجْذُومٍ فَأَدْخَلَهَا مَعَهُ فِي الْقَصْعَةِ ثُمَّ قَالَ كُلْ ثِقَةً بِاللَّهِ وَتَوَكُّلاً عَلَى اللَّهِ
“The Messenger of Allah (ﷺ) took the hand of a leper and made him eat with him, and said: “Eat, with trust in Allah and reliance upon Allah.” 
Second: While some scholars accepted this. They said Rasullullah PBUH have instructed us to run away from a leper and be cautious and not to eat or drink with them. Hence, it is impermissible for a person who knows this but he has to run away from a leper.
Scholars argued presenting a narration from al-Zuhri, where Umar Ibn al-Khattab RA once said to Mu’aiqib (Ibn Abi Fatimah al-Dausi) RA who was a leper, saying:
اجْلِس مِنِّي قَيْدَ رَمْحٍ
“Sit a pole distance away from me.”
While in another narration from Kharijah bin Zaid, he said:
كَان عُمَر إذَا أتى بِالطَّعَامِ وعِندَهُ مُعَيْقِيب قَالَ كُلْ مِمَّا يَلِيكَ، وَايمُ الله لَو غَيركَ بِهِ مَابِكَ مَاجَلسَ مِنِّي على أدنى مِن قَيدِ رَمْحٍ
Umar when the meals are served for him when Mu’aiqib was with him said: “Eat from what is near you. By Allah, if it is any other person than you with this disease, I’d not allow them to sit near me less than a pole away from me.”
(See Syarah Sahih al-Bukhari, by Ibn Battal, 9/413)
Coming back to the above question, the Prophet PBUH once permitted a shepherd who complained of his health when they are in Medina to exit and move to a higher place and stay there until they recovered. However, the ruling of the permissibility of escaping from a place where there is an epidemic is exempted if it is for the plague.
If it is the plague, then whoever is in the area are prohibited from leaving the place based on a sahih hadith from the Prophet Muhammad PBUH. However, scholars of madhhab Maliki said it is makruh for a person to escape from the place where there is the plague to another place. 
This is the same with the issue of COVID-19 that is currently rampant, where most countries implement the approach to quarantine or MCO, whether it is for a person or certain places. Thus, the ruling is similar to the above-discussed issue. 
We end this discussion with the supplication:
اللَّهُمَّ إِنَّا نَعُوذُ بِكَ مِنَ البَرَصِ، وَالْجُنُونِ، وَالْجُذَامِ، وَمِنْ سَيِّئِ الْأَسْقَامِ
“O Allah, I seek refuge in Thee from leprosy, madness, elephantiasis, and evil diseases.”
 Narrated by al-Bukhari (5728)
 Narrated by al-Bukhari (5707)
 Narrated by Ibn Majah (3542)
 See Ahkam al-Quran, 2/366-367
 Also see our published book Covid-19 Fiqh: Q&A.