I know that in Western Europe, the title of Emperor was essentially reserved for the Holy Roman Emperor but realistically, what was really stopping, say, the King of Spain, to change his title to Emperor of Spain?
Well first off, the Holy Roman Empire and the the Kingdom of Spain were not a part of the 'Ancient Times' you mention. They are squarely medieval. Why a leader did or didn't call him/herself an emperor/empress are different questions if you're talking about the classical era versus the Middle Ages.
Why did few ancient rulers call themselves Emperors? Well first, the term itself is a Latin one. It evolved from whatever magistrate held 'imperium' or power over a specific province or region. This was gradually expanded until the entire 'empire' was brought under the 'imperium' of one man - the 'imperator' or Emperor. This wasn't a clean process by any means and I'm probably short shifting it, so apologies.
So, ancient rulers didn't call themselves specifically 'Imperator' because it would be odd for the Persian or a Celt or an Indian to use a Latin term for their supreme ruler. In their own language, they might very well have meant the same thing. 'Shahanshah' for instance, the name of the Sassanid ruler, means roughly 'King of Kings', or, basically, Emperor. All depends on what language they used and what language you're familiar with. King was often used instead of emperor or other titles by English translators without much thought.
If we are addressing the Middle Ages, as your example suggests? Well as far as my understanding goes, this is primarily due to the fact that titles were a very stratified and heavily regulated element of European society during the Middle Ages. The Holy Roman Emperor could call himself that because of a long, long lineage of Holy Roman Emperors stretching far back, essentially to Charlemagne. In addition, he was given power partly by the fact that he was elected by the various powerful princes, Archbishops and other electors of the Holy Roman Empire. Their power in deciding the ruler of the Empire would be abrogated if they suddenly started referring to themselves as Emperors all of a sudden.
Actually, it's interesting you use the case of Spain and the Holy Roman Empire, as The Ruler of Spain, Carlos V, actually was also the Holy Roman Emperor as well. So in fact the king of Spain did refer to himself as Emperor, and quite rightly.
I do know of some instances where there are exceptions, as there always are. In one famous case, Brian Boru was referred to as 'Imperator Scottorum' or Emperor of the Irish in one Chronicle. While this is pretty cool, it should also be remembered that the Irish had a knack for referring to rulers of almost any rank as some sort of King, thus it might mean something different than we assume now.
Altogether, in the Middle Ages the title of Emperor was a fraught term that brought with it a lot of cultural baggage that wasn't always so pleasant. Often Kings wielded more power than some Holy Roman Emperors, but that didn't mean they were immediately tempted to upset a centuries long institution for the sake of their own grandeur. After all, King itself is quite a grandiose title.
I will post more sources once I'm not writing on my phone, but one of my favourite, and most cited, books on Medieval Kingship and traditions is Frank Barlow's The Feudal Kingdom of England, 1042-1216
Hope some of this is helpful!