Those Who breached the Sabbath were turned into Monkeys, butThose Who prohibited Their Actions were saved
Allah said that the people of this village were divided into three groups, a group that committed the prohibition, catching fish on the Sabbath, as we described in the Tafsir of Surat Al-Baqarah. Another group prohibited them from transgression and avoided them. A third group neither prohibited them, nor participated in their action. The third group said to the preachers,
("Why do you preach to a people whom Allah is about to destroy or to punish with a severe torment"). They said, `why do you forbid these people from evil, when you know that they are destroyed and have earned Allah's punishment' Therefore, they said, there is no benefit in forbidding them. The preachers replied,
The detailed discussion of the events contained in the above verses have been produced in Surah Al-Baqarah (under verses 58-60). Those interested may refer to those verses for details.
The Holy Prophet ﷺ has been asked to warn the Israelites present in his time by reminding them the events related in these verses. The events referred to in these verses are clear and require no explanation.
Tazkirul Quran
Maulana Wahiduddin KhanOn ayahs 166–167
This was the fate of those who contravened the rule of the Sabbath. But ‘God made them apes,’ does not mean that their faces became the faces of apes; it means that their character became ape-like; their hearts and thinking were like those of apes instead of human beings. (Tafsir al-Qurtubi). Now, man’s becoming an ape means that he becomes so insensitive after taking action again and again against the dictates of his wisdom and conscience, that any fine feelings are completely driven out of him. Whatever desire takes shape in his heart, he puts it into action. Whenever anyone comes into his ambit, he will attack his honour and property. If he has a complaint against anybody, he will immediately set about degrading that person. If he has any differences with anybody, he will start denigrating him. If he finds somebody to be an impediment in his way, he will immediately start fighting with him. A true man is one who applies the bridle of God to himself, and an ape is one who unrestrictedly starts doing whatever his base self asks him to do. Preventing others from doing evil is, in fact, a way of proclaiming that one has discharged one’s responsibility. So, when God’s scourge falls upon a group, those people who are extremely disgusted with evil, to the extent of becoming its preventers, are saved from this punishment. A human being is a creature into whom the Creator has infused intelligence and conscience. In a human being when some desire takes shape, his wisdom and conscience immediately becomes activated and the question arises as to whether the fulfillment of that desire is proper or not. In the case of an ape, however, there is no impediment between his wish and its fulfillment. Whatever comes into his mind he immediately does it. It is not necessary for him to think about his wish, nor need he be ashamed after pursuing it.
Uthmani text of the Madinah mushaf (King Fahd Complex). Translation: Saheeh International. Tafsir via Quran.com.