Pension expenditure in Spain is out of proportion from any point of view, though. I'll provide links to some graphs because I think they give more information than my words could:
So yes, the reason why we are underinvesting in pretty much everything is basically pensions. GDP is up, tax collection is up, debt to GDP is sligthly decreasing... but pension expenses keep growing at a fast pace so there's less and less money for everything else. And I say this with both of my parents earning the maximum pension, so I don't have an axe to grind, but it's just reality.
It's a trend that is pretty much inevitable for a country where birth rates have been dropping starkly for decades, so that less people generating the taxable income that pays for those pensions enters the workforce, than those who leave it.
I agree it's hard or maybe even impossible to entirely fix the problem, but there are degrees. You can at least try to mitigate it. And this is not done in Spain even in the slightest.
Check the charts above, pensions have been strictly updated with inflation in the last decades, while salaries (including both public salaries, fixed by the government, and private ones) haven't.
If salaries losing purchasing power haven't caused widespread riots, surely pensions doing the same wouldn't, and the impact on the budget would be noticeable. Of course, it would cause the party in government to lose votes, which is why it's not done.
At the same time, medical advances make it so that retirees live longer than before: https://relojpublico.es/poblacion/esperanza-de-vida
If someone has solutions that would not cause widespread riots, I'm sure most goverments of countries in a similar situation would be all ears.