فَجَعَلْنَاهَا نَكَالاً
So We made this punishment an example,
means, Allah made the people of this village, who violated the sanctity of the Sabbath,
نَكَالاً
(an example) via the way they were punished.
Similarly, Allah said about Pharaoh,
فَأَخَذَهُ اللَّهُ نَكَالَ الاٌّخِرَةِ وَالاٍّوْلَى
So Allah, seized him with punishing example for his last and first transgression. (79;25)
Allah's statement,
لِّمَا بَيْنَ يَدَيْهَا وَمَا خَلْفَهَا
for those in front of it and those behind it,
meaning, for the other villages.
Ibn Abbas commented,
"Meaning, `We made this village an example for the villages around it by the manner in which We punished its people."'
Similarly, Allah said,
وَلَقَدْ أَهْلَكْنَا مَا حَوْلَكُمْ مِّنَ الْقُرَى وَصَرَّفْنَا الاٌّيَـتِ لَعَلَّهُمْ يَرْجِعُونَ
And indeed We have destroyed towns (populations) round about you, and We have (repeatedly) shown (them) the Ayat (proofs, evidences, verses, lessons, signs, revelations, etc.) in various ways that they might return (to the truth and believe in the Oneness of Allah ـ Islamic Monotheism).(46;27)
Therefore, Allah made them an example for those who lived during their time as well as a reminder for those to come, by preserving their story. This is why Allah said,
وَمَوْعِظَةً لِّلْمُتَّقِينَ
and a lesson for Al-Muttaqin (the pious),
meaning, a reminder.
This Ayah means,
"The torment and punishment that this village suffered was a result of indulging in Allah's prohibitions and their deceit. Hence, those who have Taqwa should be aware of their evil behavior, so that what occurred to this village does not befall them as well."
Also, Imam Abu Abdullah bin Battah reported that Abu Hurayrah said that the Messenger of Allah said,
لَاا تَرْتَكِبُوا مَا ارْتَكَبَتِ الْيَهُودُ فَتَسْتَحِلُّوا مَحَارِمَ اللهِ بِأَدْنَى الْحِيَل
Do not commit what the Jews committed, breaching what Allah has forbidden, by resorting to the lowest types of deceit.
This Hadith has a good (Jayid) chain of narration.
Allah knows best