It was a very different world back then.
First, there was no shortage of private capital willing to take risks. They did not expect the state to bear much of the risk and effectively guarantee profits.
Second, the railways had a near-monopoly of transport. They were up against canals, and to an extent, coastal shipping, but there was no road transport worth mentioning beyond local delivery and certainly no airlines.
Third, the most profitable railways were those with heavy coal and mineral traffic. That trade has virtually vanished.
We maintain a railway system mainly for social and economic reasons. It is subsidised, although not to the extent that is common in Europe. Without that subsidy, almost the whole passenger network would be bankrupt. There are limited freight trains that make enough profit for them to be viable (which is why they are privately operated) but they benefit from not bearing the whole of the infrastructure costs. Whether they would still be viable if passenger trains vanished is questionable,