Electric trains do.
For the rest, they don't because of lack of storage.
A diesel locomotive has a huge engine block, a generator, a large radiator, and electric motors on the axles. You can turn the motors into generators when you want braking, but where are you going to put the electricity? All the space (and weight) is already used.
Yes, they have batteries - enough to crank the engine when it has been turned off. Not enough to run the electric motors on the wheels, though.