The operating carrier who caused the delay/missed connection etc. is the one responsible in the event of there being multiple carriers within a booking - so IB are liable here.
It doesn't actually matter who you booked with, although in this case having booked with IB probably simplifies things since, as a minimum, they can't really argue the toss over the downgrade reimbursement. Note, however, that you aren't entitled to as much in downgrade reimbursement as you might expect, since both MAD-LHR and LHR-NCL are flights of under 1500km, so EU/UK261 only entitles you to 30% of the fare and YQ for those flights, pro-rata to the SJO-MAD-LHR-NCL mileage.
You can escalate the matter to AESA, the Spanish equivalent of the UK's CAA, for Alternative Dispute Resolution. I can't comment on how effective that process is and I don't think we've had many reports of it here - perhaps there are more on the IB subforum. Otherwise you are looking at having to take legal action, which is no fun against foreign airlines ever since the B-word meant that UK residents became ineligible to use the EU Small Claims procedure...