This was when the polytheists were banished from the Sacred Mosque.
Muhammad said: "bearing witness" is a circumstantial qualifier (hal). The meaning is: It was not for them to maintain the mosque while they were acknowledging their disbelief.
هَذَا حِينَ نُفِيَ الْمُشْرِكُونَ عَنِ الْمَسْجِدِ الْحَرَامِ.
قَالَ مُحَمَّدٌ: ﴿شَاهِدِينَ﴾ حَالُ؛ الْمَعْنَى: مَا كَانَتْ لَهُمْ عِمَارَةُ الْمَسْجِدِ فِي حَالِ إِقْرَارِهِمْ بالْكفْر.