Good luck setting up a railway or anything else with the Taliban running the show.
The last thing the Chinese would want to do is open up that border.
They are just happy to see America defeated because, make no mistake, China sees the USA as an enemy.
It isnt just China that wants that railway, Iran wants it too. Iran wants a pipeline to sell oil directly to China and it wants a transport route to increase trade with China.
While it's true that most Afghanis are Sunni and Iran is Shia, they have historical and cultural ties that make them willing to cooperate with Iran.
Afghanistan is also a poor country that will welcome Chinese investment.
As for the border, the Taliban want to keep their people inside the country and the Chinese aren't hindered by woke politics, they have no problem gunning down anyone that even looks like a terrorist. Nobody is gonna be able to sneak across that border, especially because that border is mountainous, arid, inhospitable and constantly under satellite surveillance.
The Taliban are in a strong negotiating position, they have 3 countries that want their cooperation: China, Iran and Russia. All have economic interest in that region.
If they play their cards right, they can become a regional power. They will be flush with Chinese investment money, supported by Iran's oil and armed with Russia's weapons (and also American weapons left behind)...