Schengen residents do need a visa to enter the UK, except if only in transit, connecting to a flight elsewhere departing no later than 23:59 the next day. In that case, they can be let in simply by presenting their passport, residence permit, filled-out landing card and e-ticket for the connecting flight.
Source: the GOV.UK website
However, if flying from Spain directly to the UK and then back, this doesn't count as transit, so you would need a visa.
If you need to stay no longer than until 23:59 the next day, one solution could be to book the return flight with a stopover. However, since flights within Europe are frequent, it'll be hard to prove that you need to stay in the UK for as long as you need simply for the purpose of transit. Plus, you would have to lie about the purpose of your trip, which will land you in hot water if you're caught.
So, all-in-all, get a standard visitor visa.