It's a lot more profitable (in the good way) to build the rails and stations first, on cheap land, and have the cities grow around those. The builders of the railway get to capture the increased land value, rather than having to buy (or otherwise pay off) huge uninterrupted tracts of very expensive developed land containing thousands of homes etc. Buy low, sell high and all that.