The financial titans of the day invested in and built them.
Govt helped by donating land for right of way.
Sometimes they didn’t get built and lost money. Cornelius Vanderbilt’s New York Central tried to compete with the Pennsylvania at one time, but the route became the PA Turnpike after he abandoned the effort.
They all ran their own passenger service until Amtrak was formed to bail them out.
The NYCentral and Pennsylvania merged and then went bankrupt, there’s a book about the fall of the Penn Central.
There have been many failed railroad companies in the US.
But didn’t block any of the AI companies who stole from everyone.