The first thing to say is that EU membership, clearly, does not prevent you having a state-owned national railway company. This is because the UK is the only major member state where one of these doesn't operate the vast majority of services.
From France to Portugal, Spain to Germany, Italy to Poland, passenger rail is overwhelmingly run by the country's respective version of British Rail. Unlike in the UK, these were never privatised and broken up.
The suggestion that EU state aid rules would prevent you from subsidising these companies is also wrong: Article 93 of the EU's treaty specifically exempts "the coordination of transport" from state aid regulations.
EU member states make great use of this exemption: ticket prices can be absurdly low, especially for commuters. In Belgium, where I live, train tickets are practically given away for free: a weekend six-hour round trip between Brussels and Arlon can be bought on the day for £19 return. For those over 65, there's a flat charge of £6 for a return ticket anywhere in the country.
Other EU countries are going further: Luxembourg subsidises its railways so much that it has decided there is no point in even bothering to collect fares anymore, and from the beginning of 2020 it's just going to make all of its public transport free, for everyone.
So EU rules do not prevent you having a public railway company, or from subsidising it to whatever absurd degree you fancy. But it's important to be clear what restrictions the EU does place on member states' railways: or to be precise, what restrictions it will place on them.
This is because the situation in the EU is changing: in 2016 the bloc approved a package of legislation called the Fourth Rail Package, which will come into force from 2023. This includes a series of new rules whose intention is to bring the private sector and market competition into the railways. Looking at the situation in member states now might not be a very good guide to what they will look like in a few years' time.