Allah concludes surah al-Tahreem with the following ayaat where He says:
ضَرَبَ اللَّهُ مَثَلًا لِلَّذِينَ كَفَرُوا اِمْرَأَةَ نُوحٍ وَامْرَأَةَ لُوطٍ كَانَتَا تَحْتَ عَبْدَيْنِ مِنْ عِبَادِنَا صَالِحَيْنِ فَخَانَتَاهُمَا فَلَمْ يُغْنِيَا عَنْهُمَا مِنَ اللَّهِ شَيْئًا وَقِيلَ ادْخُلَا النَّارَ مَعَ الدَّاخِلِينَ * وَضَرَبَ اللَّهُ مَثَلًا لِلَّذِينَ آمَنُوا اِمْرَأَةَ فِرْعَوْنَ إِذْ قَالَتْ رَبِّ ابْنِ لِي عِنْدَكَ بَيْتًا فِي الْجَنَّةِ وَنَجِّنِي مِنْ فِرْعَوْنَ وَعَمَلِهِ وَنَجِّنِي مِنَ الْقَوْمِ الظَّالِمِينَ * وَمَرْيَمَ ابْنَتَ عِمْرَانَ الَّتِي أَحْصَنَتْ فَرْجَهَا فَنَفَخْنَا فِيهِ مِنْ رُوحِنَا وَصَدَّقَتْ بِكَلِمَاتِ رَبِّهَا وَكُتُبِهِ وَكَانَتْ مِنَ الْقَانِتِينَ
Allah presents an example of those who disbelieved: the wife of Nuh and the wife of Loot. They were under two of Our righteous servants but betrayed them, so those prophets did not avail them from Allah at all, and it was said, “Enter the Fire with those who enter.” And Allah presents an example of those who believed: the wife of Fir’awn, when she said, “My Lord, build for me near You a house in Paradise and save me from Fir’awn and his deeds and save me from the wrongdoing people.” And [the example of] Maryam, the daughter of ‘Imran, who guarded her chastity, so We breathed into her Our Ruh, and she testified to the truth of the Words of her Lord, and His Scriptures, and she was of the devoutly obedient. [66:10-12]
Imam al-Sa’di, in his book of tafsir, writes the following commentary:
هذان المثلان اللذان ضربهما الله للمؤمنين والكافرين، ليبين لهم أن اتصال الكافر بالمؤمن وقربه منه لا يفيده شيئًا، وأن اتصال المؤمن بالكافر لا يضره شيئًا مع قيامه بالواجب عليه.
These are two examples which Allah has struck of the believers and the disbelievers in order to clarify to them that a connection of a kaafir to a mu’min and his closeness to him does not benefit the kaafir at all, and that the connection of a mu’min to a kaafir does not harm the mu’min at all, so long as he establishes his duties to him [i.e. giving him his due rights, not being unjust to him, etc.]