The Messenger of Allah ﷺ said concerning Madinah, "Whoever commits an offense in it, or shelters one who commits an offense, or claims allegiance to someone other than his own guardian, upon him is the curse of Allah, of the angels, and of all people. Allah will accept from him neither ransom nor recompense."
وبإسناده قال قال رسول الله ﷺ المدينة من أحدث فيها حدثا أو آوى محدثا أو تولى غير مولاه فعليه لعنة الله والملائكة والناس أجمعين لا يقبل الله منه صرفا ولا عدلا
Its isnad is sahih, being the same as the previous one. Bukhari narrated the hadith with a similar wording in 3/26, the virtues of Madinah, the sanctity of Madinah, and Muslim in 2/999, number 1371, in the Hajj, the virtue of Madinah.