The Escorial and the Buen Retiro are just two among the extraordinarily expensive palaces built by the Habsburgs while they were engaged in expensive wars they could not afford. Just the Escorial and its contents have been estimated as costing more than all the revenue Queen Elizabeth I had access to during her entire reign of 45 years.
Did anyone within the kingdom/s explicitly protest the Habsburgs building of palaces when state ends could surely have been better met with other expenditures? How did the Spanish crown react to these criticisms?
Well, the simple answer is at the time, they were still exploiting incredible amounts of gold and silver from the New World, specifically, the mines of Zacatecas and Potosi. The volume of precious metal was so large that it was believed that it would never run out, so it didn't seem to matter if they ran up some debt. Unfortunately, the Spanish tended to spend their money on those palaces and on art, and so the wealth they brought back often times ended up being paid out to other nations and their craftsmen, who instead invested the money and actually boosted their long-term standing in Europe.
The answer is that these palaces served an actual political function and if one removes foreknowledge of Spain's bankruptcies, they make a degree of sense. The Habsburgs and their elite courtiers intended these palaces to be integral to their domestic and international standing. Each of the two examples the OP asked, the Escorial and the Buen Retiro, have both a logic to their construction and architecture that can be sometimes lost looking at them from the vantage point of 2014. Bautista designed the Escorial to be a royal palace that showcased both the majesty and the piety of the Habsburg monarch. The Escorial was to be a pantheon of the Habsburgs, it housed the crypt of Philip II's father as well as Philip's growing collection of saint's relics. Philip II timed his residency in the Escorial to time with holy days such as Easter. The religious nature of the Escorial should not be underestimated. Although the Potosi and other New World sources were significant sources of crown revenue for Philip II, John Lynch estimates that New World revenue never exceeded the ecclesiastical the state accrued from the Spanish church.
While the Escorial represented a fusion of religious and temporal power, the Retiro attempted to glorify the Spanish empire's power and military strength. Brown and Elliot have done a great job parsing out the political message Olivares intended this pleasure palace to express. For Olivares, the Retiro was a symbol of the Union of Arms, the composite imperial structure of the Habsburg patrimony. The Hall of Realms contained massive paintings of contemporaneous Habsburg victories, such as Velazquez's justly famous Surrender of Breda. The pleasure aspects of the Retiro such as fine art or collections of tapestries were a contrast to its relatively sedate exterior. Invitation to the palace was to be a sign of true elite status. As the early modern state evolved, having reliable courtiers became essential to the functioning of the government. One of the functions of early modern court life was to bind courtiers into the personal regimen of the monarch.
Both the Retiro and the Escorial represent a general trend in the growing sedentary nature of European monarchs. Medieval monarchs could be quite peripatetic. When Philip II complained to his father about the poor state of Madrid's palaces, his father told him "kings do not need residences." But the growing sophistication of the state needed a more stationary locus of power. In the sixteenth and seventeenth centuries, access to the monarch became increasingly important for political power and European monarchs became increasingly hidden from public view. Thus palaces and other cultural projects became very important ways to simultaneously express political power visible fashion and isolate the monarch from all but the elite. In this respect, the Hapsburg's were somewhat ahead of the European curve and encountered many of the same problems other European heads of states would encounter in the future.
One of these problems was that in times of distress, these massive palaces, which often had a long gestation and construction period, became an albatross around the neck of the state. Olivares's Union of Arms project collapsed in the 1640s and the Retiro was a symbol of this particular favorite's profligacy and corruption of the Spanish monarch. The Retiro's prominent iron aviary, designed to showcase the empire's power through a collection of rare birds, earned the complex the derogatory name gallinero: the chicken coop when Spain's fortunes began to sink. The Spanish crown's responses to these critiques was to try and present the individual Habsburg monarch as a model of probity. a number of Philip II and Philip IV's portraits would emphasize their modest clothing and their membership in the Order of the Golden Fleece. However, a number of Spanish monarchs would realize that there was a fine line between profligacy and spending to meet the needs of imperial statecraft.
Sources
Adamson, John. The Princely Courts of Europe: Ritual, Politics and Culture Under the Ancien ReĢgime, 1500-1750. London: Weidenfeld & Nicolson, 1999.
Brown, Jonathan, and J. H. Elliott. A Palace for a King: The Buen Retiro and the Court of Philip IV. New Haven: Yale University Press, 1980.
Elliott, J. H. The Count-Duke of Olivares: The Statesman in an Age of Decline. New Haven: Yale University Press, 1986.
Lynch, John. Spain, 1516-1598: From Nation State to World Empire. Cambridge, USA: Blackwell, 1992.