I heard the Messenger of Allah ﷺ say, "If you hear that it has broken out in a land, do not enter it. And if it breaks out in a land while you are there, do not leave fleeing from it." He meant the plague.
حدثنا القعنبي عن مالك عن ابن شهاب عن عبد الحميد بن عبد الرحمن بن زيد بن الخطاب عن عبد الله بن عبد الله بن الحارث بن نوفل عن عبد الله بن عباس قال
سمعت رسول الله ﷺ يقول إذا سمعتم به بأرض فلا تقدموا عليه وإذا وقع بأرض وأنتم بها فلا تخرجوا فرارا منه يعني الطاعون
Bukhari narrated it in the Book of Medicine, Chapter on what is mentioned concerning plague, hadith no. 5729, and Muslim narrated it in the Book of Greetings, Chapter on plague, ill omens, divination, and similar matters, hadith no. 2219, from the hadith of Malik through this chain. It is also found in Muwatta (Yahya's version) 2/894-896, and this is an abridgment of it.