The Sonata #14 by Beethoven did not get the subtitle “Moonlight” until many years after the composer’s death.
The name “Moonlight Sonata” comes from remarks made by the German music critic and poet Ludwig Rellstab. In 1832, five years after Beethoven’s death, Rellstab likened the effect of the first movement to that of moonlight shining upon Lk Lucerne in Switzerland.
Within ten years, the name “Moonlight Sonata” (“Mondscheinsonate” in German) was being used in German and English publications. Later in the nineteenth century, the sonata was universally called by this name.