Question: Why is Spanish sometimes referred to as Castilian or castellano?
Answer: An answer to that question requires a brief look at how the Spanish language developed to its current form. What we know as Spanish is primarily a derivative of Latin, which arrived on the Iberian Peninsula (the peninsula that includes Spain and Portugal) around 2,000 years ago. On the peninsula, Latin adopted some of the vocabulary of indigenous languages, becoming Vulgar Latin. The peninsula's variety of Latin became quite well entrenched, and with various changes (including the addition of thousands of Arabic words), it survived well into the second millennium.
For reasons more political than linguistic, the dialect of Vulgar Latin that was common in what is now the north-central portion of Spain, which includes Castile, spread throughout the region. In the 13th century, King Alfonso supported efforts such as the translation of historic documents that helped the dialect, known as Castilian, become the standard for educated use of the language. He also made that dialect the official language for government administration.
As later rulers pushed the Moors out of Spain, they continued to use Castilian as the official tongue. Further strengthening Castilian's use as a language for educated people was Arte de la lengua castellana by Antonio de Nebrija, what might be called the first Spanish-language textbook and one of the first books to systematically define the grammar of a European language.
Although Castilian became the primary language of the area now known as Spain, its use didn't eliminate the other Latin-based languages in the region. Galician (which has similarities to Portuguese) and Catalan (one of the major languages of Europe with similarities to Spanish and French) continue to be used in large numbers today. A non-Latin-based language, Euskara or Basque, is also spoken by a minority.
In a sense, then, these other languages — Galician, Catalan and Euskara — are Spanish languages and even have official status in their regions, so the term Castilian (and more often its Spanish equivalent, castellano) has sometimes been used to differentiate that language from the other languages of Spain.
Today, the term "Castilian" is used in other ways too. Sometimes it is used to distinguish the north-central standard of Spanish from regional variations such as Andalusian (used in southern Spain). Sometimes it is used, not altogether accurately, to distinguish the Spanish of Spain from that of Latin America. And sometimes it is used simply as a synonym for Spanish, especially when referring to the "pure" Spanish promulgated by the Royal Spanish Academy (which itself preferred the term castellano in its dictionaries until the 1920s).
In Spain, a person's choice of terms to refer to the language — castellano or español — sometimes can have political implications. In many parts of Latin America, the Spanish language is known routinely as castellano rather than español.