Prayer does not compete with God's knowledge or justice. In Islamic theology, prayer is itself one of the means through which God brings about what He eternally knows and wills, while the result remains subject to wisdom that is often wider than immediate worldly victory.
The argument in its strongest form
The objection has real force if prayer is imagined as an attempt to persuade God to violate justice. Suppose two people dispute a matter, one is genuinely wronged and the other is dishonest. If God already knows the truth and guarantees that justice will prevail, then the innocent person's prayer seems unnecessary. But if prayer can change the result, it appears that a more intense or eloquent supplicant might receive an outcome that belongs to the wrongdoer. Either prayer is ineffective, or it seems to make justice arbitrary.
This argument correctly rejects the idea that prayer is a way of manipulating God. It does not, however, establish that prayer has no meaningful effect.
What prayer means within divine decree
God's eternal knowledge includes not only the final outcome but also the actions and causes leading to it. If a person prays and is helped, God knew eternally that this person would pray and that the prayer would be among the means of help. The prayer does not surprise God, add information to Him, or defeat His decree.
"And your Lord has said, 'Call upon Me; I will respond to you.' Indeed, those who disdain My worship will enter Hell humiliated.
Quran 40:60
This is comparable to other ordinary means. Food relieves hunger, medicine treats illness, and seeking legal protection may prevent oppression. Saying that God already knows the result does not make these actions pointless. Prayer is a spiritual cause, and sometimes God joins it to a changed circumstance, protection from harm, guidance, or reward in the Hereafter.
Justice is not the same as immediate worldly success
The premise that God grants victory only to the objectively innocent person is also too simple. The Quran does not promise that every worldly contest will visibly reward the morally innocent. Wrongdoers may prosper temporarily, and sincere people may suffer. Worldly events are tests, and complete judgment belongs to the Hereafter.
"Do not think that Allah is unaware of what the wrongdoers do. He only delays them for a Day when eyes will stare in horror."
Quran 14:42
Nor does an answered prayer prove that God has declared the person righteous. A dishonest person may obtain what they ask for as a test, through ordinary causes, or for a limited worldly purpose. Conversely, a sincere prayer may be answered by preventing a greater harm or by storing its reward for the Hereafter. The Prophet Muhammad (PBUH) taught that supplication is itself an act of worship, not merely a device for obtaining a preferred event.
What the objection does and does not show
The objection shows that prayer cannot be treated as a guarantee that one's preferred side is morally right, nor as a mechanism that forces God to abandon justice. It does not show that prayer is causally empty. Islam holds together both truths: God knows and governs all things, and human prayer, effort, repentance, and restraint are real means within that governance.
So prayer does not replace justice or excuse wrongdoing. It places the servant before the Just Judge, seeking help while accepting that the wisest answer may be victory, delay, protection, guidance, or final recompense.