Dr. Bat Sheva Garsiel in her book "Bible, Midrash and Quran", pp. 181-182, discusses this passage and suggests two possible explanations for the origins of this idea:
What @BruceJames brought, that Ezra is compared to Moshe in the gemara.
In the apocryphal 4th Ezra, it says that Ezra, upon completing his duties on earth, rose to the heavens and became known as the "Scribe of the Most High" (Syriac 4th Ezra/2 Esdras, 14:49)
The second possibility falls in line with what Tabari, one of the classic Quran commentators, says about this passage: Tabari, according to Garsiel, heard from Jews of his time that Jews do not have such a tradition. And so he wrote that this tradition was held either by one Jew named Pinchas, or by a small sect of Jews. He also wrote that he heard from Wahb ibn Munabbih, a Muslim who wrote works on Jewish stories and traditions, that Jews hold the belief that when the First Temple was destroyed, all of the Torah was lost and Ezra remembered all of it and wrote it down. This particular claim is a key part of 4th Ezra (see chapter 14).
Garsiel wrote the connection to 4th Ezra in the name of Speyer, who also suggested (pg. 413) something she didn't mention, which is that perhaps Muhammed knew a Jewish-Christian sect that worshipped Ezra in the manner that some Christians worship Malkitzedek.