Quran 17:16 does not teach that God morally commands people to commit sins and then punishes them for obeying Him. The verse has a genuine interpretive question, but both its wording and the wider Quran make clear that divine command is not a command to wickedness.

What the objection fairly observes

The verse says that when God intends to destroy a town, He commands its affluent people, they commit transgression in it, and the decree of punishment becomes due against it. Read in the most immediate way, this can sound as though God orders the very conduct for which He later condemns them. Some classical exegetes did understand amarna in the sense of commanding them, usually explaining that God commanded obedience but they chose disobedience. The critic is right that this creates a real interpretive issue, not something to dismiss with a careless translation.

And when We intend to destroy a town, We command its affluent ones, but they defiantly disobey therein; so the word becomes justified against it, and We destroy it completely.

Quran 17:16

What "command" means in the verse

Arabic amara can refer to a moral command, but Quranic usage also distinguishes God's creative decree from His command of what He loves and approves. God may decree that an act occur without approving it morally. Pharaoh's tyranny, for example, occurred within God's decree but was plainly condemned.

Classical tafsir preserves more than one explanation of this verse. Al-Tabari, al-Qurtubi, Ibn Kathir and others discuss the reading that God commanded obedience, after which the affluent rebelled. Other early interpretations understand the verb as meaning that God increased their number, power, or prosperity, and they then became corrupt. These are not desperate modern evasions; they arise from recognized Arabic usage and the early exegetical tradition.

The context also identifies the affluent as the leading class whose privilege produces rebellion. It does not say that God implants sin in innocent people and then punishes them for it. The destruction follows their actual fisq - deliberate departure from obedience - and the punishment becomes due only after that wrongdoing.

The Quran's moral rule is explicit

The proposed contradiction disappears if God's decree is distinguished from His moral approval. The Quran directly denies that God commands indecency:

Indeed, Allah does not command immorality. Do you say about Allah what you do not know?

Quran 7:28

Thus, if "We command" in 17:16 means a moral command, it means a command to obey, which they violated. If it describes God's decree, empowerment, or granting of prosperity, it still does not mean approval of their crimes. In either case, the people are punished for freely chosen transgression, not for obeying a divine order to sin.

So the verse does establish that God may allow a prosperous ruling class to become a cause of public corruption and may decree a town's destruction after persistent wrongdoing. It does not establish that God commands sin as sin, nor that divine justice punishes people for carrying out a sinful command from God.