Many wonder, including those who do not believe, about the Mahdi, who he was and if he truly existed. Yes, he did exist. He was a young boy through whom the Holy Spirit chose to speak. One can read this Qur'an passage and find it a help in thinking about him.
Surah 16:102
Say: The Holy spirit has revealed it from your Lord with the truth, that it may establish those who believe and as a guidance and good news for those who submit.
The meaning is that the Mahdi received truth from the Holy Spirit in order to bring comfort to those who follow and believe. I am not saying that the Qur'an requires belief in the Mahdi by those who do not follow that school or sect of Islam. I am saying that the Mahdi was real and was a vessel through whom the Holy Spirit spoke, so that in the many years later believers of that school will have the comfort of knowing this authentic blessing from God in their sacred lineage. This passage explains in general why the Holy Spirit chooses certain people through whom he speaks, and can certainly be applied to the Mahdi.
I hope that you find this information helpful.