Yes, but it's hard to use a train the way the 9/11 attacks used planes. They were able to take the planes and magnify the damage, casualties, and spectacle and they had a high degree of freedom in picking targets. Much harder to pull that off with a train; you'd make the news, but not stun the world.
I have never understood why, post 9/11, planes were not modified to remove the cabin to cockpit door, and make the cockpit door a separate entrance. This would more or less completely remove the possibility of a second 9/11 attack, and would render airplanes no more attractive a target than any other group of several hundred people.
Pilots need access to a toilette, but also there are rare cases where pilots need to look out of side windows. There's also flights with crew changes. And the very rare case of crew incapacitation. A case where a pilot needed to gain access to the cockpit but couldn't, Germanwings Flight 9525.