The Holy verse says:
"And when We intend to destroy a city, We command its affluent but they defiantly disobey therein; so the word comes into effect upon it, and We destroy it with [complete] destruction." (17:16)
The Verse explanation:
First let's explain the verse. Actually there are three explanations for the verse
God, of course knows everything about us because we are His own creation. When God knows that the people in a city are too corrupted to do good "when we intend to destroy a city". This "intention" is based on God prior knowledge that they will live and die corrupted. They haven't committed anything yet, but He knows their hearts are so wicked and soon they will show their corruption. For a merciful and just God, this prior knowledge is not sufficient to punish them. God knows that their hearts are corrupted but He never punishes unless He warns them first may be they will repent that's the meaning of the word "We Command".
"We Command" means He sends them messengers to command them to do good and obey the orders of God. When they refuse to obey, God destroys that city because of the deeds that the people committed by their own free will.
The meaning of "We intend" is when a city is corrupted and it's people are sinners who do not have any sense of morality, God knows that these people deserve to be punished for their deeds. In this explanation, they have already committed evil deeds. But because He is patient and merciful, He does not punish then for what they did, instead he sends them messengers to "COMMAND" them to do good and stop their corruption. If they insist on their corruption and total disregard to any sense of morality or virtue then they deserve to be punished for the deeds they insisted stubbornly on doing despite the messengers, despite the warnings, despite the miracles that messengers show to prove that they were send by God. Just then the severe punishment is done which is total destruction of that city.
In Arabic when a patient is close to dying we say "the patient wants to die", meaning that he is approaching his death. Similarly when we say "a merchant wants to be bankrupt", meaning that he is so close to bankruptcy. Of course the patient does not intend to die or the merchant does not intend to bankrupt himself, but it is an Arabic figure of speech.
So when God says: "when we intend to destroy a city" it means that God is very close to destroying the city due to their evil deeds, but because he is merciful He "Commands" them meaning He sends messengers to command them to obey God. If they insist on their wickedness, then they deserved to be punished.
The proof of this is found in another verse (18:77), the verse says: "So they set out, until when they came to the people of a town, they asked its people for food, but they refused to offer them hospitality. And they found therein a wall about to collapse, so al-Khidhr restored it. [Moses] said, "If you wished, you could have taken for it a payment." The Arabic words used for the wall that was about to collapse were "they found therein a wall that wants to collapse" , but for the translation to convey the required meaning the verse is translated to: " And they found therein a wall about to collapse ". So "want to do something" in Arabic can actually mean "very close to doing something" and the Holy Quran already used this figure of speech in the verse (18:77).
Who is Punishing the city?
In the verse (17:16) notice that God promised to punish the city Himself, He did not order the Muslims to destroy the city, He said that He Himself will handle the punishment. Where is the call for war here? Actually it is a lesson to Muslims that for such a city, they are NOT allowed to interfere in it claiming that they are destroying it for the sake of God because God clearly stated that HE will handle the punishment, they are NOT allowed to interfere as long as that city does not harm the Muslims or attack them.
Why Punish the city?
Punishment is a necessity for the continuity of life peacefully. If you do not punish the wrong dower then this attitude will encourage more people to do the same conduct and so life will turn to a wild jungle where the strong does what he wants without fear of punishment.
At the same time, threatening the wrong doer and facing him with the fact that he will pay for his deeds can make him reconsider his attitude and may actually change his behavior.
That is why a parent punishes his child, to threaten him and warn him that he will pay for what he did, at the same time sets an example to his brothers and sisters that that kind of behavior will not go unpunished. It is not that the parent is evil or blood thirsty, it is all about the continuity of life in the right direction.
When Does God punish a city?
To punish a city God has first to send them a messenger to warn them, sometimes several messengers are sent. In the Holy Quran God says: "And never would We punish until We sent a messenger." (17:15)
"That is because your Lord would not destroy the cities for wrongdoing while their people were unaware." (6:131)
Why the " affluent"?
Simply because they are the ones rejoicing Gods' gifts more than the poor so they should be more grateful to God. If a poor man steals, this may be understandable but when a rich man steals, this is a definite proof that he is corrupted. He is doing wrong because he wants to not because he needs to.
God did not create a city to destroy it. He created man to live righteously so everybody can live in peace. No one should try to offend others or hurt them or deny them their rights in any way. If people insist on being corrupted and oppressing others, God then sends a messenger (and sometimes more than one) to try to guide people to the right way to live and promise them a comfortable peaceful life if they stick to what God orders them to do because this is the only guarantee you do not trespass on others rights, so the whole community can live in peace.
Messengers encourage people to be righteous by explaining that the results of righteous behavior is clear in life (peaceful coexistence and prosperity) and in the afterlife (heaven). If people do not respond then messengers warn people and clarify the inevitable results of wrongdoing which is reflected in life (unsafe, disturbed violent societies) and in the afterlife (hell). If they still insist on doing wrong then they deserve to be punished to set an example to the whole world that doing wrong insistently has it's destructive consequences. Setting example is a safe guard to other societies from facing similar consequences.
Let's try to think for a second here, which strategy creates violent societies. Telling people they have to live righteous, where everybody should respect the others' rights or else they will be punished OR
letting people live the way they choose without even attempting to warn them, letting the strong eat the weak and oppress him till at the end the weak starts defending himself by attacking the strong and hence creating a wild jungle where everybody does what he wants disregarding any morals.
Which society do we need to create in our world. Shouldn't the strong feel that there is a tremendous force (GOD) capable of punishing him and that this force is just and will bring the weak his rights. Where is the call for violent here? Is it violent to tell the wrong doer that he will pay unless he changes his behavior or Is the real call for violence is when you let a society go on living without respect for others' rights.
Notice here that the verse did not mention anything about imposing a certain religion on people. It is NOT that God wants you to follow a certain religion by force it is about following the right conduct that the messengers clearly clarified.