To understand this, you must know several things:
Charles V (Charles I of Castille, Aragon, Navarre) actually preferred Seville as the "seat" of government of Spain, but he was very much a traveling monarch in reality. His son Philip II chose Madrid due to its geographically center position. This was not a choice that wasn't criticized. It made communication and travel to and from his overseas dominions quite a bit longer. But Philip II built the Escorial and other buildings and his successors largely followed his lead.
The prosperous parts of today's Spain were not so prosperous in the 16th century. Aragon, Catalonia, and Valencia was suffering from economic malady, the plague, and then the expulsion of Moriscos. Castille was the strongest in terms of manpower and economy.
Another question, why did they choose Madrid over Toledo?