RyanAir is to blame, as you followed the rules precisely for UK landside transit with an EU residence permit. Unfortunately, passenger recourse against such problems is difficult. You could try to claim EC261 compensation for denied boarding, and/or seek passenger rights help from Spanish authorities at seguridadaerea.gob.es.
The rules are shown in Timatic, available at iatatravelcentre.com. I don’t know why another answer incorrectly determined that you need a visa, although the rules are tricky and maybe the airline made the same mistake.
Here’s (in bold) the relevant rule I get from Timatic with origin Spain, destination Russia, transit United Kingdom for less than 24 hours, citizenship Russia, residence permit from Spain. (I also get the same output with origin Russia, destination Spain):
Visa United Kingdom
TWOV (Transit Without Visa):
Nationals of Russian Fed. transiting through London: Gatwick (LGW), Heathrow (LHR) or Manchester (MAN) with a confirmed onward ticket for a flight to a third country on the same calendar day. They must stay in the international transit area of the airport and have documents required for the next destination.
Nationals of Russian Fed. making a landside transit with a confirmed onward ticket for a flight to a third country that departs before 23:59 the next day. They must:
~ have a common format residence permit issued by Spain, and
~ clear immigration, and
~ have documents required for the next destination.