Reasons for The Occultation Of Imam Mahdi (A.S.)
 
1. Free From Allegience Of Every Tyrant

Amirul Momineen Alt (A.S.) said,

"Certainly', when the Qaem from among us shall arise, he will not have the allegience of any one upon his neck. It is for this reason that his birth is secret and his person is in Ghaibat."
(Kamaaluddin Vol.1. Pg.303)

It must be mentioned that all of our Imams had to pledge allegience to every tyrant ruler except for a short period during the rule of Umar ibne Abdul Aziz. This was because, on the face of it, it would seem that they are not against the ruler, In this way they could protect Islam. In the absence of popular support, the Imams were left alone and thus they entered into an understanding with the rulers. Thus even Imam Husain (A.S.) for a particular period did not find it necessary to revolt against the regime of Muawiya. 
In this regard Hazrat Mahdi (A.S.) says:

"Verily each of my ancestors had the oath of allegience, upon their necks, of their contemporary tyrant rulers. But I will reappear at such a time that I will not have any tyrant's allegience upon my neck."
(Ghaibat Tusi Pg.292, Kamaaluddin VoL2. Pg.485)

2. Test Of The People

Imam al Kazim (A.S.) said,

"My son ! when the fifth descendant of the seventh of the Imams is not visible to you ! It is when Allah will test your belief. Ghaibat is inevitable for the Master of this affair. Till the time when the religion is completely transformed, and only a few people will have belief in him. My son ! That Ghaibat, It is a
trial through which Allah, the Almighty tests His servants."
(Ghaibat-e-Toosi Pg.166 & 337. Al Kafi vol.1 Pg.336. Kamaaluddin vol.2 Pg.359 and 360. Kifayatul Asar Pg.264-265)

3. Fear Of The Enemy

Imam Musa al-Kazim (A.S.) said,

"The Qaem is the one who will purify the earth from the enemies of Allah, the High and the Mighty. And he will fill the earth will justice and equity just as it is filled with injustice and tyranny. He is the fifth of my descendants. He will go into occultation due to the fear of his own (life)."
(Kamaaluddin vol.2 Pg.361. Kifayatul Asar Pg.265-266)
According to common sense it is necessary for man not to throw away his precious life without a legitimate aim. Thus, the prophets (A.S.) and the Imams (A.S.) have taught the people that it is their duty to protect their life under every circumstance and should never put their life in danger. Therefore it is the duty of the last of these exalted personalities to protect himself till the time of his reappearance when he will establish the new world order.

4. Weakness And Lack Of Co-operation Of The People.

Imam Mahdi (A.S.) said.

"If our shias; may Allah help them in His obedience; would have fulfilled their covenant with united hearts then there would have. been no delay in our meeting, and they would have been blessed with our visitation at the earliest, along with the recognition of truth and confirmation of our rights."
(Al Ihtejaj vol.2 Pg.602)