A similar case is the report:
“The Prophet, may Allah bless him and grant him peace, went out on the day of Badr and told his Companions where the polytheists would fall, saying: ‘This is where so-and-so will fall, and this is where so-and-so will fall.’ Then he entered the shelter and began supplicating earnestly, saying: ‘O Allah, fulfil for me what You have promised me.’”
His knowledge that he would be victorious did not preclude his taking the means by which victory would be granted to him: seeking Allah’s help.
Some people have erred here, supposing that a supplication whose fulfilment is already known—such as the supplication at the end of Surah al-Baqarah—is prescribed solely as an act of worship. This resembles the claim made by some that supplication is nothing more than an act of worship, because what has been decreed will happen whether one supplicates or not.
Such a person should be told: If Allah has made supplication a means of attaining the desired outcome that He has decreed, how can it come about without supplication? This is akin to their saying: “Should we not abandon deeds and rely on what has been written?”
What further clarifies this is that Allah already knows and has written that He will create His creatures, provide for them, cause them to die, and bring them to life. Can it then be thought that this prior knowledge and writing make these things independent of His creating them, His power, and His will? The same applies to Allah’s knowledge of the deeds His servants will perform and of their becoming blessed or wretched through them, just as He knows, for example, that a man will become ill or die through ingesting poison, wounding himself, or the like.