In The Name of Allaah, The Most Merciful, The Bestower of Mercy.
Allaah [The Most High] said:
وَمَآ أَرۡسَلۡنَا فِى قَرۡيَةٍ۬ مِّن نَّبِىٍّ إِلَّآ أَخَذۡنَآ أَهۡلَهَا بِٱلۡبَأۡسَآءِ وَٱلضَّرَّآءِ لَعَلَّهُمۡ يَضَّرَّعُونَ
ثُمَّ بَدَّلۡنَا مَكَانَ ٱلسَّيِّئَةِ ٱلۡحَسَنَةَ حَتَّىٰ عَفَواْ وَّقَالُواْ قَدۡ مَسَّ ءَابَآءَنَا ٱلضَّرَّآءُ وَٱلسَّرَّآءُ فَأَخَذۡنَـٰهُم بَغۡتَةً۬ وَهُمۡ لَا يَشۡعُرُونَ
And We sent no Prophet to any town (and they denied him), but We seized its people with suffering from extreme poverty and loss of health and calamities, so that they might humble themselves (and repent to Allah). Then We changed the evil for the good, until they increased in number and in wealth, and said: “Our fathers were touched with evil (loss of health and calamities) and with good (prosperity, etc.)”. So We seized them of a sudden while they were unaware. [Surah Al-A’raaf. Aayaat 94-95]
[وَمَآ أَرۡسَلۡنَا فِى قَرۡيَةٍ۬ مِّن نَّبِىٍّ إِلَّآ أَخَذۡنَآ أَهۡلَهَا بِٱلۡبَأۡسَآءِ وَٱلضَّرَّآءِ لَعَلَّهُمۡ يَضَّرَّعُونَ – And We sent no Prophet to any town (and they denied him), but We seized its people with suffering from extreme poverty and loss of health and calamities, so that they might humble themselves (and repent to Allah)]- Meaning: [The Prophets] called them to worship Allaah alone and forbid them from Shirk, but they did not submit to him, except that Allaah put them to trial through poverty, illnesses and various types of afflictions; so that when afflicted, their souls will be humbled- humble themselves to Allaah and submit to the truth.
However, if that did not bring about any good, their haughtiness continued and their transgression increased, they were given much provision, their bodies were granted wellbeing and the calamity was removed; until they became numerous in number, their provision became abundant, they rejoiced due to Allaah’s blessings and bounty and forgot the calamities they have been through. [وَّقَالُواْ قَدۡ مَسَّ ءَابَآءَنَا ٱلضَّرَّآءُ وَٱلسَّرَّآءُ – And they said, “Our fathers were touched with evil (loss of health and calamities) and with good (prosperity, etc.)”] – Meaning: This is a normal occurrence and it has not ceased to [be the case] in the early and later generations- sometimes they are in a situation of ease and at other sometimes they are in a situation of hardship; sometimes in a situation of happiness and at other times in a situation of grief, in accordance with the changing circumstances in every era and days that are good and days that are not so good. So, they thought that the [calamities] were neither an admonition nor a reminder, nor a gradual plan for their final destruction and punishment; until when they became filled with joy and rejoiced due to what they were granted, and the worldly [life became the most valuable thing in their hearts, minds, thoughts], they were suddenly seized with punishment; [بَغۡتَةً۬ وَهُمۡ لَا يَشۡعُرُونَ – of a sudden while they were unaware]- Meaning: They did not expect [or perceive] that the destruction will occur and thought that they had all the powers of disposal over that which Allaah gave them, will remain forever and there was not be any change from that.
An Excerpt from Tafsir As-Sadi. Slightly paraphrased