Answer:
He could still “hear” in his head. All he had to do was transcribe what he “heard” and knew onto staff paper. Composers do not need to physically hear the music they are writing—they know how it will sound. Basically he already knew the basics of music, and so used his head in place of his ears.