Al-Mahdi (as) is one of us, from the Ahl al-Bayt. Allah will purify him in one night [in other words, He will accept his repentance or equip him with spiritual knowledge and wisdom]. (Sunan Ibn Majah, Kitab al-Fitan, Kahraman Press, Vol. 10, Ch. 34, p. 348)
Islamic scholars interpret this hadith as follows:
… The betterment of Hazrat Mahdi (as) in a single night refers to his being given eminent status. He cannot obtain this status by work or endeavor. As stated by Almighty Allah in the Qur'an, this blessing bestowed on the Prophet (saas) has also been given to Hazrat Mahdi (as). In verse 52 of Surat ash-Shura, Almighty Allah has said: "Accordingly We have revealed to you a spirit (Ruh) by Our command. You had no idea of what the Book was, nor belief. Nonetheless, We have made it a Light by which We guide those of Our servants We will. Truly you are guiding to a Straight Path." Hazrat Mahdi (as) is the most virtuous and the most perfect person of his time in matters of religion. This shows his greatness, the exalted nature of his status, and the greatness of his rank. (Mulla Ali Qari, Al-Mashrab al-Wardi fi Mazhab al-Mahdi)
Bediüzzaman Said Nursi also refers to Hazrat Mahdi (as) in this way:
He will send a radiant person as both the GREATEST INTERPRETER OF THE LAW, and the GREATEST RENEWER, and RULER, and the MAHDI, and as GUIDE, and SPIRITUAL POLE, and that person will be from the Family of the Prophet… (Bediuzzaman Said Nursi, Letters / Twenty - Ninth Letter - Seventh Section, p. 515)