صحيح البخاري Sahih Bukhari كتاب فضائل المدينة The Book About The Virtues Or Al-Madina.
بَابُ الْمَدِينَةُ تَنْفِي الْخَبَثَ:

(10) Chapter. Al-Madina expels Al-Khabath (all the evil and bad persons, etc.).

2 hadith
Hadith 1883
حَدَّثَنَا عَمْرُو بْنُ عَبَّاسٍ ، حَدَّثَنَا عَبْدُ الرَّحْمَنِ ، حَدَّثَنَا سُفْيَانُ ، عَنْ مُحَمَّدِ بْنِ الْمُنْكَدِرِ ، عَنْ جَابِرٍ رَضِيَ اللَّهُ عَنْهُ ، " جَاءَ أَعْرَابِيّ النَّبِيَّ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ ، فَبَايَعَهُ عَلَى الْإِسْلَامِ ، فَجَاءَ مِنَ الْغَدِ مَحْمُومًا ، فَقَالَ : أَقِلْنِي ، فَأَبَى ثَلَاثَ مِرَارٍ ، فَقَالَ : الْمَدِينَةُ كَالْكِيرِ تَنْفِي خَبَثَهَا وَيَنْصَعُ طَيِّبُهَا " .
Narrated Jabir: A bedouin came to the Prophet and gave a pledge of allegiance for embracing Islam. The next day he came with fever and said (to the Prophet ), "Please cancel my pledge (of embracing Islam and of emigrating to Medina)." The Prophet refused (that request) three times and said, "Medina is like a furnace, it expels out the impurities (bad persons) and selects the good ones and makes them perfect."
Hadith Reference Sahih Bukhari / The Book About The Virtues Or Al-Madina. / Hadith: 1883
Hadith Grading محدثین: أحاديث صحيح البخاريّ كلّها صحيحة
Hadith 1884
حَدَّثَنَا سُلَيْمَانُ بْنُ حَرْبٍ ، حَدَّثَنَا شُعْبَةُ ، عَنْ عَدِيِّ بْنِ ثَابِتٍ ، عَنْ عَبْدِ اللَّهِ بْنِ يَزِيدَ ، قَالَ : سَمِعْتُ زَيْدَ بْنَ ثَابِتٍ رَضِيَ اللَّهُ عَنْهُ ، يَقُولُ : " لَمَّا خَرَجَ النَّبِيُّ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ إِلَى أُحُدٍ رَجَعَ نَاسٌ مِنْ أَصْحَابِهِ ، فَقَالَتْ فِرْقَةٌ : نَقْتُلُهُمْ ، وَقَالَتْ فِرْقَةٌ : لَا نَقْتُلُهُمْ ، فَنَزَلَتْ : فَمَا لَكُمْ فِي الْمُنَافِقِينَ فِئَتَيْنِ سورة النساء آية 88 ، وَقَالَ النَّبِيُّ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ : إِنَّهَا تَنْفِي الرِّجَالَ ، كَمَا تَنْفِي النَّارُ خَبَثَ الْحَدِيدِ " .
Narrated Zaid bin Thabit: When the Prophet went out for (the battle of) Uhud, some of his companions (hypocrites) returned (home). A party of the believers remarked that they would kill those (hypocrites) who had returned, but another party said that they would not kill them. So, this Divine Inspiration was revealed: "Then what is the matter with you that you are divided into two parties concerning the hypocrites." (4.88) The Prophet said, "Medina expels the bad persons from it, as fire expels the impurities of iron."
Hadith Reference Sahih Bukhari / The Book About The Virtues Or Al-Madina. / Hadith: 1884
Hadith Grading محدثین: أحاديث صحيح البخاريّ كلّها صحيحة