According to EU Directive from 1983 regarding the ´competent state´ re healthcare benefits for pensioners.
¨Which is the competent State? For the right to benefits in kind (healthcare), the competent State, which bears the cost of the benefits (22), is:
» the Member State of residence, if the person concerned is in receipt of a pension from that State entitling him/her to benefits in kind (even where the person concerned is in receipt of pensions from one or more Member States);
» the Member State responsible for paying the pension entitling the person concerned to benefits in kind if s/he resides there, if the person concerned is not in receipt of a pension in his/her State of residence (even where s/he is in receipt of benefits in kind in this State by virtue solely of his/her residence);
» the Member State responsible for paying a pension entitling the person concerned to benefits in kind if s/he resides there, to whose legislation the pensioner was subject for the longest period, if s/he is in receipt of pensions from several Member States other than the Member State where s/he resides.¨
Put simpler, if you are resident in a EU country where you also contributed as worker, either employed or self employed and receive a pension as a result of your contributions, then your healthcare as a pensioner should also be paid for by that country, irrespective of the fact that you might have more contribution years in another EU country.
Practical example: if you have a pension from the UK and from Spain, you reside in Spain, then you are not entitled to S1 nor EHIC from the UK, but have entitlement to healthcare through your Spanish pension and TSE for trips to other EU countries, including the UK.
Another example: if you have a pension from the UK and from Spain, but reside in yet another EU country, you will need to apply for a S1 from the country where you contributed longest, to transfer your healthcare entitlement from that country to your country of residence. Same goes for EHIC.