Yes, an electric motor turning at a slow speed can produce tremendous torque and very little torque at high speed. It is the exact opposite for the ICE. I don't know if they are still running in Seattle, Washington State, but some time ago there were overhead-electric powered buses there which worked very well for climbing the hilly streets.You are mixing things that are not mutually exclusive.
Both gasoline and diesel engines (as well as other IC engines) can be either two-stroke or four-stroke). All four combinations have optimal operating speeds, but can work over a wide range of speeds.
The big motivation for locomotives using electric drives is the need to produce high torque at essentially zero rotational speed and do so for an extended period of time. Electric motors can be designed to do this very efficiently and robustly. Engines need transmissions and, for zero speed torque, friction clutches or fluid power couplings. For the power output that a locomotive needs, these would be huge, expensive, inefficient, and maintenance intensive.