While Imām Mahdī’s Hujjah was clear [certain], why before his birth did some Shiites considered Imām Ali or his son “Muḥammad ibn Hanafiyyah”, Nafs Zakiyyah, Imām Ṣādiq, Imām Kādhim, Imām Hādī’s son “Sayyid Muḥammad, or even Imām Askarī as Imām Mahdī?!
The correct answer includes 4 parts:
1- Although in some Aḥādīth which are about Imām Mahdī (mGehr)’s rise, by the Messenger of God (pbuh&h) and his Ahl al Bayt (pbu th), it has been clarified that he is definitely the son of 11th Imām “Askarī (pbuh)”, because the people knew all Ahl al Bayt (pbu th) as “The best guide for people” and “Guided by God”; therefore, facing cruelty and violation, they took refuge to one of them as “Imām Mahdī (mGehr)” [It was a sort of psychological need to a divine Imām]. They would also take some other people with themselves. They were often simple-hearted or ignorant people, and just in some cases politics intervened.
2- This type of Shiites often didn’t last more, and joined the other leaded Shiites or left the place, at last.
3- In some cases, some people considered others as Imām Mahdī, due to the religious skepticism that was privileged at that time. But it was fortunately disappeared soon.
*Al-Nafs al-Zakiyyah is the title of a person called Muḥammad ibn al-Ḥasan. He is called “al-Nafs al-Zakiyyah” (the Pure Soul) in Aḥādīth, because of his asceticism and worship. He is from the progeny of Imām al-Huṣayn (pbuh), and is thus a Huṣaynī Sayyid.
Source: https://makarem.ir/maaref/