That's a remnant of the past, where only a nation state could afford massive projects such as creating a railway line crisscrossing throughout a massive country.
Since the last couple of decades we see private companies investing in railway lines, including high-speed railway corridors. We also see a major liberalization push in Europe to decouple railway operators from infrastructure maintainers, and now there are plenty of private companies operating railway services across the world. In Spain alone there are 2 or 4 private companies providing high-speed railway connections between major urban centers.
The reasons for this are complicated and nuanced though.
Governments think they push the financial burden of transport maintenance on the people (and its a good tool to register and control people too, but thats not a strong consideration I wouldn’t wager), so they fervently cut spending on public transport and curtail cycling infrastructure in favour of cars.
But roads themselves operate at a crazy financial loss and are one of the reasons governments are in crazy debt (which nobody wants to acknowledge).
This is because road maintenance is significantly more expensive than building new roads. Which means that road use becomes heavily subsidised (much more than trains cost per user) but the cost of vehicle ownership, despite that heavy subsidy, is still enormous and one of the largest expenses an average person can have.
Specifically because of massive government investment in road infrastructure in preference of railways. This would be about like the government deciding to funds DCs directly...