All children can compose in their heads like Mozart, it's not a special skill
In a video from Robert Gjerdingen's exemplary "Child Composers" YouTube channel, he discusses the remarkable ability of the child students at the music conservatories of Naples to compose in their heads complex contrapuntal musical ideas. This is very much like how Wolfgang Amadeus Mozart was popularly noted to have composed music.
"Conservatory boys had similar powers with relation to counterpoint, or multiple musical voices. They could will them into being in their minds with all the interactions of the various voices. It seemed like magic but it was the result of training."
Total immersion in music at these Neapolitan conservatories over years enabled these children to recognize, imitate and compose a wealth of musical information. Years of singing Italian Solfeggio, practicing partimenti exercises at the keyboard, written counterpoint classes and instrumental lessons created musicians so skilled at the craft of music that music could easily be dreamed up in their heads. It was, a complete music education.
In the video above, Professor Gjerdingen mentions an Italian composer by the name of Tomasso Traetta. He studied with Nicola Porpora in Naples and Porpora himself as a graduate of the music conservatory Poveri di Gesù Cristo, where the primo maestro was either Don Gennaro Ursino (1688-1695) or Gaetano Greco (1695-1706). Joseph Haydn remarked that he learned the "true fundamentals of composition" from Porpora while working as his valet for a period of time.
Here is Traetta's Stabat Mater, mentioned in the video above.
Traetta was not the only composer able to imagine music into being as mentioned in the video,
"This was a skill shared by composers all over Europe."
So if composing in one's head wasn't a particularly special skill in the 18th century, why do we view this skill as remarkable today?
Such an ability requires a immersion in music to such an extent that the student learns the common phrases, the ability to recognize the phrases, experiment with them and create new ones. Let us consider the eminently practical pedagogical of the Neapolitan conservatories when crafting curriculum for the modern student.