According to the Royal Spanish Academy (RAE), the Spanish word comes from Provencal espaignol, and this from the Latin medieval Hispaniolus, which means "de Hispania" (Spain).
The Latin form HĬSPĀNĬOLUS comes from the Latin name of the province of HĬSPĀNĬA that included the Iberian peninsula, rather, of its ultracorrecta form. It should be remembered that in late Latin the / H./ was not pronounced. The opening of the / Ĭ / Latin brief in / e / would have given therefore in protorromance: ESPAŇOL (U).
Another hypothesis holds that Spanish comes from Occitan espaignon.65 Menéndez Pidal offers another etymological explanation: the classical Hispanus or Hispanicic took in Latin vulgar the suffix -one (as in Burgundian, Breton, Frisian, Lappish, Saxon, etc.) and * Hispanione was passed in old Castilian to Spanish, "then dissimilating the two noses came to Spanish, with the ending -ol, which is not used to mean nations."
The other name, Castilian, comes from the Latin castellanus, which means Castile, medieval kingdom located in the central part of the Iberian peninsula and origin of this language.