Outside of America most of the developed world has fine networks for both. It's just that the rails are optimized for passenger travel and the road is generally where freight goes. China is kind of odd in that they have both heavy freight and passenger traffic on their railroads; the HSR network was built in part to free up the traditional railway network to serve more freight trains.
Part of it is that China has a lot of money. Part of it is that right now China doesn't really care about debt (China Railways has $770B in debt). And part of it is that the population is so large that they can afford to essentially build a second whole railway network and a highway network. There's also a difference in strategy; European and Japanese rail development is slow, requires working with communities, and HSR is directly routed to city centers, whereas China for its HSR networks prefers connecting megahub stations outside of the city center, more similar to how airports work.
There's also the question of if they can actually afford to maintain this network long term; it features many more viaducts and tunnels than equivalent rich country networks, even in flat terrain. And some design decisions are questionable; it's not uncommon to see, for example, strange merging patterns for lanes or a lack of shoulders on the highway network.
Part of it is that China has a lot of money. Part of it is that right now China doesn't really care about debt (China Railways has $770B in debt). And part of it is that the population is so large that they can afford to essentially build a second whole railway network and a highway network. There's also a difference in strategy; European and Japanese rail development is slow, requires working with communities, and HSR is directly routed to city centers, whereas China for its HSR networks prefers connecting megahub stations outside of the city center, more similar to how airports work.
There's also the question of if they can actually afford to maintain this network long term; it features many more viaducts and tunnels than equivalent rich country networks, even in flat terrain. And some design decisions are questionable; it's not uncommon to see, for example, strange merging patterns for lanes or a lack of shoulders on the highway network.