You build your track dead straight - like, not conforming to the surface direct through the crust straight. Now the train accelerates downhill for the first half of the journey, and decelerates uphill for the second, neatly coming to a stop at the destination. Oddly enough, in the spherical cow universe where you build this, all the maths cancels such that you get a constant travel time regardless of the start and end locations. On earth it's about 40 minutes
If you accelerate the passenegers to the same speed as the train while they board, then you can solve one of those problems. I suggest firing them out of a canon.
I was assuming the rails are strong enough to keep the train on the Earth, but I guess infinite friction from the movement and rotation of the Earth probably isn't survivable by any railway material. Hypothetically, if you had a material unaffected by gravity (train), and a material that is absolutely invincible (the rails, and they are anchored to the center of the Earth), now does it work?
No, the problem is not gravity, is that the train attached to earth has velocity dictated by the Earth movements, and keeps it because of inertia. In your theoretical experiment, the train would be launched on space at constant velocity.
The problem isn't gravity, it's friction. The train would functionally be in orbit. The reason why things can't be in orbit at ground level is not because of gravity but because of friction (incl. air resistance).
If you eliminated friction (vacuum tube, frictionless surface, etc.) you could indeed have the train moving without any additional energy after getting it up to speed (and if you get it up to orbital speeds, the frictionless surface isn't even necessary). However, this isn't really practical (obviously).
If there is a nugget of a good idea in here, it's a train that never needs to accelerate or decelerate, just maintain a constant speed. Much of the energy of a train is lost in the stop-and-start.