God is aware of all the realities and secrets. Therefore, all events and creatures are present in His essence and nothing is absent from it. With His power, He is aware of the cunningness and oppression of all the oppressors and has the ability to prevent it from happening. But His wise, eternal and unchanging rule and tradition is that all events are according to physical causes and reasons and occur according to regular channels. Based upon this, it is not right to violate His wise traditions and rules to protect the Prophet and Imams or promote religion.
In other words, although God has in some cases made the Prophet and Imams aware of the schemes and dangers that the enemies were planning against him and their followers, and they were permitted to use miracles and extraordinary powers granted to them by God, they could stop them, but in most cases, they had the responsibility to use the method of cause and effect that is available for all of the people including enemies, to defend themselves and fight against the enemies. If it was permitted to become victorious by using irregular methods and resources not available to the average person, then they would not have been models to train humans.
Additionally, this world would not have been the place of responsibility, test, and volition, if there was a path other than the normal cause and effect.
God is aware of all the realities and secrets of the past, present and future of all things. T herefore, all events and creatures are present in front of Him; due to His encompassing existence over all things, nothing is absent from His presence. The Qur’an says in this regard: Not an atom’s weight escapes your Lord in the earth or in the sky; nor anything smaller than that nor bigger, but it is in a manifest book. 
Imam Ali also says: He is aware of all secrets and all minds. His surrounding nature encompasses and overpowers everything. 
Among some of things known by the Almighty God is the power, schemes, and oppression of the oppressors. He has the capacity to prevent those but He has refused, because the affairs of the world should be done through its causes.  His wise tradition and law is that all things should be done through physical causes and effects and occur through regular channels. All of the divine traditions and laws are eternal and never change.  Based upon this, it is not right to violate His wise traditions and laws to protect the Prophet and Imams or promote religion.
Since the divine messengers were responsible for the guidance of humans in all physical and spiritual realms and the Imams, who were their successors, had this same responsibility, in many cases they also have the knowledge of the unseen,  like the knowledge of the time and location of their martyrdom.   But this does not mean that no matter was hidden from them.   Based on this, the cases which God made the Prophet and Imams aware of the schemes and dangers the enemies had for them and their companions, were special and unique cases (in which they were responsible to use miracles and divine extraordinary powers to thwart the enemies). In most cases, they had the responsibility to use the method of cause and effect that is available for all of the people including enemies, to defend themselves and fight against them, and to be content with the results. Therefore, one aspect of the life and battles of the Prophet and Imams in facing oppression and injustice is that they are an example and model for all humans throughout history. If it was permitted to become victorious by using irregular methods and resources not available to the average person, then they would not have been models to train humans and it would not be meaningful in the path of establishing truth and justice.
Another perspective is that if the administering of affairs was other than the regular cause and effects, and through miracles He allowed them to be victorious over the enemies, the world would not be a place of responsibility, test and volition. All affairs would be forced and without the volition of humans which would violate the divine wisdom and the purpose of the world and humans.
The apparent defeat in battles or the martyrdom of the Prophets or Imams does not mean the absence of divine assistance. But the true victory is achieving the elevated goals and virtues that God has introduced to them. So based on this, their patience and perseverance till the last moments of their life and their adherence to all of the virtues till the last drop of blood, is the effect of the victory and assistance of God for all those persevere and the chosen ones, including the Prophet and Imam who attained the biggest victory and greatest triumphs.
 Nahjul-Balaghah, sermon 85, pg. 205.
 Kāfī, vol. 1, pg. 183, Jame’ al-Ahadith Software, “أَبَى اللَّهُ أَنْ یُجْرِیَ الْأَشْیَاءَ (الامور) إِلَّا بِأَسْبَاب”.
 Ahzab:62 “سُنَّةَ اللَّهِ فِی الَّذینَ خَلَوْا مِنْ قَبْلُ وَ لَنْ تَجِدَ لِسُنَّةِ اللَّهِ تَبْدیلاً ”.
 Kahf:64; Jinn:26; Aal Imran:43 and 174; Hud:51; Shura:53.
 Qara’ati, Tafsir Noor, vol. 4, pg. 245, “Of course, knowledge of the unseen isn't always a virtue and can sometimes be a flaw. For instance, the night Imam Ali (as) slept in the prophet’s sleeping place, if the imam knew that his life would indeed be saved, it would no longer be a merit for him, because in this case, everyone would be willing to sleep in the prophet’s place…”.
 Adopted from: Unseen knowledge of the imams about their martyrdom, Question 579 (website: 631).
 Subhani, Jafar, Tarikhe Payambare Islam, pg. 480. For example, in the way of Tabuk, the prophet’s camel got lost. “What kind of prophet are you who doesn’t know where his camel is?!” someone sneered. The prophet replied: “By God I only know of what God has taught me and Allah showed me where it is just now, its harness has gotten stuck in a tree in so and so place…”.
 Adopted from: The knowledge of Allah’s chosen ones, 14737 (website: 14498) .