Answer:
One does not have to hear in order to compose music on paper. The music was in his head ... he wrote down what he heard inside his brain.
He could hear the music in his mind. When he went deaf, he only used the music's paper and not sitting on the piano like when he could hear.