The next verse: ذَٰلِكَ جَزَيْنَاهُم بِمَا كَفَرُوا (Thus We punished them because of their ungratefulness.- 34:17) means that they were punished because they committed kufr. Kufr has two meanings. It could mean ungratefulness and it could mean the denial of the true faith. At this place, both meanings can be applied because they did both. They were ungrateful and they rejected the thirteen prophets sent to them.
There are two things here that are likely to raise a question. It has been said earlier that Allah Ta’ ala had sent thirteen prophets to the people of Saba'. Then, it has also been stated above that the event relating to these people and the flood of 'arim or dam transpired during the interim period after Sayyidna ` Isa (علیہ السلام) and before Sayyidna Muhammad al-Mustafa ﷺ called the period of fatrah or gap. During this period, according to the majority of Muslim scholars, simply no prophet was sent which is the reason why it is called the period of fatrah or gap. If so, the question is, how can the coming of these thirteen prophets be held as correct? An answer to this appears in Ruh ul-Ma’ ani. There it is said that from the event of the flood of the dam ('arim) being in the period of fatrah or gap, it does not become necessary that these prophets too came during that very period. It is possible that the coming of the prophets to these people dates back prior to the period of fatrah or gap while their contumacy and hostility to faith may have increased during the period of fatrah whereupon the punishment of the flood from the dam was sent upon them in the period of fatrah. Allah knows best.
The word: کَفُور (kafur) in the second sentence of verse17: وَهَلْ نُجَازِي إِلَّا الْكَفُورَ (And We do not give (such a) punishment but to the ungrateful - 34:17) is an emphatic form of: کَافِر (kafir) which means one who is very ungrateful or is an absolute disbeliever. As such, the verse could be taken to mean: 'We do not punish anyone other than the one who is very ungrateful or is an absolute disbeliever.' This, quite obviously, is counter to all those verses of the Qur'an and sound ahadith which prove that Muslim sinners will also receive the punishment of Jahannam (Hell) to the measure of their deed - even though, finally, once they have gone through their punishment, they will be taken out of the Jahannam because of their 'Iman or faith and admitted into Jannah (Paradise). To resolve this difficulty, it has been said that it does not signify punishment in some absolute sense, instead, it means a mass punishment as was sent over the people of Saba'. This one is particular to disbelievers. Such punishment does not befall Muslim sinners. (Ruh u1-Ma‘ani)
This finds support in the saying of a Ta` bai Ibn Khiyarah. He said, جَازَاُء الَعصِیَۃِ الوَھُن فِی عِبادۃِ وَاضِیقُ فِی المَعِیشَۃِ وَالتَّعَشُّرُ فِی اللَّذَّۃِ قال لَا یُصَادِفُ لَذَّۃُ حَلَااِلَّا جَآَءہ مَن ینغصہ إیّاھا (The punishment of sin is that the sinning person becomes sluggish in acts of worship (` ibadah) his economic conditions becomes straitened, and enjoyment (itself) becomes hard to bear...' Ibn Khiyarah explained the latter part of his statement by saying, 'When one is blessed with something halal he can enjoy, there comes one or the other reason which spoils this enjoyment'. (Ibn Kathir) This tells us that the punishments given to Muslim sinners are of this nature. No open punishment hits them either from the heavens or from beneath the earth. That is particular to disbelievers.
And sage Hasan al-Basri (رح) said: صَدَقَ اللہُ العَطِیم لَا یُعَاقَب بِمَثلِ فِعلِہ اِلَّا الکَفُور ('Great is Allah and He said it right: The punishment of an evil deed exactly in proportion to it is not given to anyone but the kafur' - someone very ungrateful or absolutely disbelieving). (Ibn Kathir) This is because a believer, who is no kafur, receives some concession with respect to his or her sins as well.
An interpretation of the sense of this verse appears in Ruh-ul-Ma’ ani with reference to Kashf. There it is said that the statement is made in its real sense. Punishment as punishment is given only to a disbeliever and whatever pain is caused to a believing sinner through things like fire is only an apparent punishment. In reality, the purpose is to cleanse him from sin. This is like heating up gold in a furnace. The purpose is to remove its unwanted sediments. This holds true in the case of a believer as well. If he too is put in Jahannam as a consequence of some sin of his, it will be to burn out those elements of his body that have grown on him from consuming what is haram. Once this is taken care of, he is ready to go to Jannah and it does not take much time that he is taken out of Jahannam (Hell) and admitted into the Paradise (Jannah).