In a nutshell ... the trains can be longer because the locomotives at the front of it don't pull or brake the entire train. They are supplemented by additional locomotives in the middle of the train that help pull and brake the train. This kind of arrangement used to be seen only in mountainous areas where trains needed to climb steep grades. Now it's being used all over the place.
For a long train even on the [relative] flats, there is an ultimate tensile strength for a given rail car [especially the one right behind the loco] that should not be exceeded..