In Surat Al-A`raf, where Allah said (7:163),
(And ask them (O Muhammad ) about the town that was by the sea; when they transgressed in the matter of the Sabbath (i.e. Saturday): when their fish came to them openly on the Sabbath day, and did not come to them on the day they had no Sabbath. Thus We made a trial of them, for they used to rebel (disobey Allah).)(7:163)
The story of how Allah sent His torment on the village that disobeyed Him and broke their pledge and their covenant to observe the sanctity of the Sabbath is explained in detail in Surat Al-A`raf, where Allah said (7:163).
They even began using deceitful means to avoid honoring the Sabbath by placing nets, ropes and artificial pools of water for the purpose of fishing before the Sabbath. When the fish came in abundance on Saturday as usual, they were caught in the ropes and nets for the rest of Saturday. During the night, the Jews collected the fish after the Sabbath ended. When they did that, Allah changed them from humans into monkeys, the animals having the form closest to humans. Their evil deeds and deceit appeared lawful on the surface, but they were in reality wicked. This is why their punishment was compatible with their crime.
In his Tafsir, Al-`Awfi reported from Ibn `Abbas that he said,
(We said to them: "Be you monkeys, despised and rejected'') means, "Allah changed their bodies into those of monkeys and swines. The young people turned into monkeys while the old people turned into swine.''
Shayban An-Nahwi reported that Qatadah commented on,
(We said to them: "Be you monkeys, despised and rejected''), "These people were turned into howling monkeys with tails, after being men and women.''