According to Mouood, quoting by ThePromisedMahdi.com:
CAUSES OF OCCULTATION OF IMAM MAHDI (A.T.F.S)
The occultation of His Eminence, the Master of the age (a.s) is a necessary thing and His Eminence is not needless of it. We shall discuss those factors that rendered it an absolute necessity.
1. FEAR OF TYRANNICAL ABBASIDE REGIME
When Abbaside rulers gained power they initiated the worst of atrocities and tortures on the Holy Imams (a.s). Basically they considered the school of Ahle Bayt (a.s) and anyone who was their adherents to be eligible for extreme pressure and restrictions. They were thrown into horrible prisons and then put to death. Poets and historians have drawn a pathetic picture of the perilous circumstances suffered by the Alawite Sayyids.
Abu Ataa says:
Alas! If only the oppression of the Merwanids (Bani Umayyah) had returned and the justice of Abbasides were destroyed and thrown into the fire.
Dibil Khuzai says:
The oppression of Bani Abbas has covered everything and no one was secure from its oppression. If we regard the oppression of Bani Umayyah an expected fact, as they were enemies of Bani Hashim, how can we justify the oppression of Bani Abbas who were themselves from Bani Hashim
Yaqub bin Sikkit, an intellectual and a scholar of language says regarding Mutawakkil, the Abbaside, when he razed the tomb of the beloved one of the Holy Prophet (a.s) and harassed and tortured the visitors to his grave:
“It is true that Bani Umayyah unjustly killed the son of the daughter of the Prophet of Islam (a.s). But the Bani Abbas regretted not being present among them when they committed this crime. So their malice was expressed in mutilating the grave of the His Eminence…”
2. TEST AND TRIAL
One of the causes of the occultation of His Eminence, Imam Mahdi (a.s) is said to be the test of people. It is narrated from His Eminence, the Messenger of Allah (a.s) that he said:
“By Allah! He would go into occultation and none shall get salvation except those who have faith in the heart and whom Allah helps.”
Although the divine practice is appointed that people should be subjected to tests and trials so that those who perform better deeds may be rewarded suitably. The Almighty Allah says:
The one who created death and life so that “He may test you, which of you has the best deeds.”
He also says:
“Do men think that they will be left alone on saying, we believe, and not be tried”
The occultation of His Eminence, Imam Mahdi (a.s) is a very important component of Divine test. None has faith in it except those who have perfect belief and testify to what the Messenger of Allah (a.s) and the Purified Imams (a.s) have said regarding the occultation of His Eminence and that he does not fix the period of his occultation. Rather he should agree that the reappearance of His Eminence is upto the wise decision of the Almighty Allah. No one has any choice in it. The example of His Eminence is like that of the Hour (Qiyamat) that there is no doubt in its coming.
3. SECRETS OF THE OCCULTATION OF THE IMAM OF THE TIME
The occultation of the Awaited Imam (a.s) is explained to be one of the divine secrets and no one else has any knowledge of it. It is this same point stated by the Messenger of Allah (a.s) when he said:
“The example of the occultation of the Qaim is like that of the Hour (Qiyamat), that only the Almighty Allah is cognizant of it and that it will not come towards you but all of a sudden.”
It is narrated from His Eminence, Imam Mahdi (a.s) that he said:
“Do not put yourself into difficulty and do not ask about matters that have no material or spiritual benefit. And do not ask but pray more for the reappearance as in it lies your success; and peace be to those who follow the guidance.”
Shaykh Miqdad Siyuri says:
“The wisdom of the occultation of His Eminence, Imam Mahdi (a.s) is restricted only to Allah and its knowledge is only with Almighty Allah.”
4. NOT PAYING ALLEGIANCE TO THE OPPRESSORS BY THE IMAM OF THE TIME (A.S)
As a justification of the occultation of His Eminence, the Master of the Age (a.s), it is mentioned that the Imam (a.s) is in occultation so that he does not have to pay allegiance to any oppressive ruler. Hasan bin Ali bin Fazal has narrated from his father from Imam Reza (a.s) that he said:
“The Shias, during the absence of the son of the third of us would be like sheep that run towards the pasture but they would not find the pasture.”
Then he was asked, “O son of Allah’s Messenger! Why is it so”
He replied, “Because their Imam shall be in occultation.”
He asked, “Why ?”
He replied, “Because if he rises up with a sword he would be compelled to have the allegiance of others upon his neck.”
His Eminence, the Master of the Age (a.s) has announced that each of his predecessors had the allegiance of the tyrants on his neck but when he reappears he shall not have the allegiance of any tyrant on his neck.
The above were some of the important causes of the occultation of His Eminence, which we have explained. And the fact is that the Almighty Allah has kept His Wali and the great reformer in occultation due to the reasons best known to Him alone, which we are not aware of.