Abbas - Tanwîr al-Miqbâs min Tafsîr Ibn ‘Abbâs
(And verily there had come unto them a messenger) Muhammad (pbuh) (from among them) a Qurayshite Arab like themselves, (but they had denied him) they denied the revelation he brought to them, (and So the torment seized them) Allah's torment in the form of hunger, killing and being taken captive seized them (while they were wrong-doers) disbelievers.
And verily there came to them a messenger from among them, that is, of their own genus, being the faculty of reflection which belongs with the totality of the soul's faculties, with rational concepts and truthful opinions, but they denied him, by failing to be affected thereby and to obey its commands and prohibitions, both the rational ones and those of the Law, and by refraining from conducting themselves according to its requirements and by being little concerned therewith and not caring in the slightest to turn their attention away from that in which they were engrossed, and so, the chastisement of being veiled and deprived from the pleasure of perfection, seized them, while they were unjust and deviating from the path of virtue and failing to fulfill the dues of their companion [the messenger].
This example refers to the people of Makkah, which had been secure, peaceful and stable, a secure sanctuary while men were being snatched away from everywhere outside of it. Whoever entered Makkah, he was safe, and he had no need to fear, as Allah said:
(And they say: "If we follow the guidance with you, we would be snatched away from our land.'' Have We not established a secure sanctuary (Makkah) for them, to which are brought fruits of all kinds, a provision from Ourselves.) 28:57 Similarly, Allah says here:
يَأْتِيهَا رِزْقُهَا رَغَدًا
(its provision coming to it in abundance) meaning, with ease and in plenty,
مِّن كُلِّ مَكَانٍ فَكَفَرَتْ بِأَنْعُمِ اللَّهِ
(from every place, but it (its people) denied the favors of Allah.) meaning, they denied the blessings of Allah towards them, the greatest of which was Muhammad being sent to them, as Allah said:
(Have you not seen those who have changed the favors of Allah into disbelief, and caused their people to dwell in the abode of destruction; Hell, in which they will burn, - and what an evil place to settle in!) (14:28-29). Hence Allah replaced their former blessings with the opposite, and said:
فَأَذَاقَهَا اللَّهُ لِبَاسَ الْجُوعِ وَالْخَوْفِ
(So Allah made it taste extreme hunger (famine) and fear,) meaning, He inflicted it and made them taste of hunger after fruits of all kinds and provision in abundance from every place had been brought to it. This was when they defied the Messenger of Allah and insisted on opposing him, so he supplicated against them, asking Allah to send them seven years like the seven years of Yusuf (i.e., seven years of famine), and they were stricken with a year in which everything that they had was destroyed, and they ate `Alhaz', which is the hair of the camel mixed with its blood when it is slaughtered.
(and fear). This refers to the fact that their sense of security was replaced with fear of the Messenger of Allah and his Companions after they had migrated to Al-Madinah. They feared the power and the attack of his armies, and they started to lose and face the destruction of everything that belonged to them, until Allah made it possible for His Messenger to conquer Makkah. This happened because of their evil deeds, their wrongdoing and their rejection of the Messenger that Allah sent to them from among themselves. He reminded them of this blessing in the Ayah:
(Similarly (as a blessing), We have sent a Messenger to you from among you, reciting Our Ayat to you, and purifying you, and teaching you the Book (the Qur'an) and the Hikmah (i.e. Sunnah).) Until
(and do not be ungrateful.) 2:151-152 Allah changed the situation of the disbelievers and made it the opposite of what it had been, so they lived in fear after being secure, they were hungry after having plenty of provisions. After the believers lived in fear, Allah granted them security, giving them ample provisions after they lived in poverty, making them rulers, governors and leaders of mankind. This is what we say about the example that was given of the people of Makkah. It was also the opinion of Al-`Awfi and Ibn `Abbas, Mujahid, Qatadah, `Abdur-Rahman bin Zayd bin Aslam, and Malik narrated it from Az-Zuhri as well. May Allah have mercy on them all.
Maududi - Sayyid Abul Ala Maududi - Tafhim al-Qur'an
That habitation has not been specified here nor have the commentators definitely pointed out which that habitation was. However, there is a saying of Ibn `Abbas (which seems to be correct) that the place referred to is Makkah itself. In that case, "hunger and fear" will mean the famine which prevailed over the people of Makkah for several years during the Prophethood of Muhammad (Allah's peace be upon him).