An elected government could start re-drafting the constitution to remove the royalty from the constitution.
It would not be a easy negotiation.
If the negotiations are successful, the new constitution would need to be ratified by the Spaniards with a referendum and an election.
Title X of the Constitution establishes that the approval of a new constitution or the approval of any constitutional amendment affecting the Preliminary Title, or Section I of Chapter II of Title I (on Fundamental Rights and Public Liberties) or Title II (on the Crown), the so-called "protected provisions", are subject to a special process that requires (1) that two-thirds of each House approve the amendment, (2) that elections are called immediately thereafter, (3) that two-thirds of each new House approves the amendment, and (4) that the amendment is approved by the people in a referendum.
----- Addendum -----
If the Spanish do remove the Royalty from the constitution, then by default the Royalty ceases to exists as they would lose most of their symbolic powers (and if it is case in Spain, they would also lose their salary...