These are almost certainly subsidized tickets, financed with taxpayer money, it is common to restrict the sales to those who pay taxes in the covered area. And I don't see how it could be illegal, it is like forcing Germany to provide health care for the French and vice versa.
Maybe in some dream world. Hospital visits are usually covered, but going to a GP often involves paying in cash and only getting reimbursed later at home.
AFAIK the legal way to limit subsidized tickets is that the specific "membership" required to get the subsidized fare is available to all EU citizens - for example in Warsaw we can get lower fare based holographic stamp available from the city on the basis of paying taxes in the city - i.e. it doesn't matter what passport you hold, it matters that your tax residency is in Warsaw.
And healthcare operates by your local health system reimbursing the system in country you were visiting - you need to have European Health Insurance Card on you, from your healthcare provider, which helps route the payments appropriately.
These are almost certainly subsidized tickets, financed with taxpayer money, it is common to restrict the sales to those who pay taxes in the covered area. And I don't see how it could be illegal, it is like forcing Germany to provide health care for the French and vice versa.