The Messenger of Allah ﷺ said, "The plague is a punishment, a torment with which a people were chastised. So if it breaks out in a land while you are there, do not flee from it, and if you hear of it in a land, do not enter it."
حدثنا وكيع عن سفيان عن حبيب بن ثابت عن إبراهيم بن سعد
قال رسول الله ﷺ الطاعون رجز أو عذاب عذب به قوم فإذا وقع بأرض وأنتم بها فلا تخرجوا منها وإذا سمعتم به بأرض فلا تدخلوا عليه
Its isnad is sahih, it has already appeared at 17593 and 21715. Ibrahim bin Saad bin Malik is trustworthy, his hadith appears in the Sahihayn. Saad bin Malik is Ibn Abu Waqqas.