There is no such hadith about Jesus(PBUH) will pray Janaja of Imam Mahdi. There is a hadith about his ruling duration.
The Prophet (PBUH) said, The Mahdi will appear in my Ummah. He will appear for a minimum of 7 or a maximum of 9 years; at that time, my Ummah will experience bountiful favors like never before. It shall have a great abundance of food, of which it need not save anything, and the wealth at that time is in great quantities, such that if a man asks the Mahdi to give him some, and the Mahdi (as) will say: Here! Take! (Sunan Ibn Majah volume 2 tradition no. 5083)
Therefore Jesus/Isa(PBUH) will ascend to earth during Imam Mahdi will be among us. Then Jesus(PBUH) will take the duty of Khilafa. There could be two most probable/possible solutions according to scholars of Ahlul Sunnah Al Jamah:
- The Khilafah will be preceded upon Jesus, after Mahdi's death.
- Mahdi will step down to give the Khilafa to Jesus for some purposes.
There is no direct certain/sahih doctrine about Mahdi's death from Ahlul Sunnah Al Jamah nor his Janazah prayed by Jesus/Isa(PBUH). But the majority of scholars say that he will face a natural death. So considering the time of ascending of Isa/Jesus(PBUH) and Imam Mahdi's Khalifa's time, It can be said that during Imam Mahdi's death bed, Isa(PBUH) will be on earth, therefore he may attend his Janazah. Allah knows best.
NB: From some Israelite sources, the Messiah of Israel is accompanied by a priestly messiah(Dead sea scroll, 1QS 9:11, 1QSa 2:11-22 — from Vermes, 1997). According to their doctrine, The Messiah ben Joseph will gather the believers from around the world(more specifically people of the former kingdom of Israel, who are the lost 10 tribes) and eventually die. Then the main messiah will pray the funeral and will take the charge of kingship.