An answer to that question requires a brief look at how the Spanish language developed to its current form. What we know as Spanish Castilian 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.
For reasons more political than linguistic, the dialect of Castilian (spanish) 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 Spanich kingdom.
Today, the term Castilian is used 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 many parts of Latin America, the Spanish language is known routinely as castellano rather than espaƱol.