The film is presented in a nonlinear narrative, cutting back and forth between McCandless' time spent in the Alaskan wilderness and his two-year travels leading up to his journey to Alaska. The plot summary here is told in a more chronological order.
In May 1992, Christopher McCandless (Emile Hirsch) arrives in a remote area just north of the Denali National Park and Preserve in Alaska and sets up a campsite in an abandoned city bus, which he calls The Magic Bus. At first, McCandless is content with the isolation, the beauty of nature around him, and the thrill of living off the land. He hunts wild animals with a .22 caliber rifle, reads books, and keeps a diary of his thoughts as he prepares himself for a new life in the wild.
Two years earlier, in May 1990, McCandless graduates with high honors from Emory University in Atlanta, Georgia. Shortly afterwards, McCandless rejects his conventional life by destroying all of his credit cards and identification documents. He donates $24,000, nearly all of his savings, to Oxfam and sets out on a cross-country drive in his well-used, but reliable Datsun B210 to experience life in the wilderness. However, McCandless does not tell his parents, Walt (William Hurt) and Billie McCandless (Marcia Gay Harden), or his sister Carine (Jena Malone) what he is doing or where he is going, and refuses to keep in touch with them after his departure, causing his parents to become increasingly anxious and eventually desperate.
At Lake Mead, Arizona, McCandless' car is caught in a flash flood, causing him to abandon it and begin hitchhiking. He burns what remains of his cash and assumes a new name: "Alexander Supertramp." In Northern California, McCandless encounters a hippie couple named Jan Burres (Catherine Keener) and Rainey (Brian H. Dierker). Rainey tells McCandless about his failing relationship with Jan, which McCandless helps rekindle. In September, McCandless arrives in Carthage, South Dakota and works for a contract harvesting company owned by Wayne Westerberg (Vince Vaughn), but he is forced to leave after Westerberg is arrested for satellite piracy.
McCandless then travels on the Colorado River and, though told by park rangers that he may not kayak down the river without a license, ignores their warnings and paddles downriver until he eventually arrives in Mexico. There, his kayak is lost in a dust storm, and he crosses back into the United States on foot. Unable to hitch a ride, he starts traveling on freight trains to Los Angeles. Not long after arriving, however, he starts feeling "corrupted" by modern civilization and decides to leave. Later, McCandless is forced to resume hitchhiking, after he is beaten by the railroad police.
In December 1991, McCandless arrives at Slab City, in the Imperial Valley region of California, and encounters Jan and Rainey again. There, he also meets Tracy Tatro (Kristen Stewart), a teenage girl who shows interest in McCandless, but he rejects her because she is underage. After the holidays, McCandless decides to continue heading for Alaska, much to everyone's sadness. One month later, while camping near Salton City, California, McCandless encounters Ron Franz (Hal Holbrook), a retired man who recounts the story of the loss of his family in a car accident while he was serving in the United States Army. He now occupies his time in a workshop as an amateur leather worker. Franz teaches McCandless the craft of leatherwork, resulting in the making of a belt that details McCandless' travels. After spending two months with Franz, McCandless decides to leave for Alaska, despite this upsetting Franz, who has become quite close to McCandless. On a parting note, Franz gives McCandless his old camping and travel gear, along with the offer to adopt him as his grandchild, but McCandless simply tells him that they should discuss this after he returns from Alaska; then, he departs.
Four months later, at the abandoned bus, life for McCandless becomes harder, and he becomes less discerning. As his supplies begin to run out, he realizes that nature is also harsh and uncaring. In the pain of realization, McCandless concludes that true happiness can only be found when shared with others, and he seeks to return from the wild to his friends and family. However, he finds that the stream he had crossed during the winter has become wide, deep, and violent due to the snow thaw, and he is unable to cross. Saddened, he returns to the bus, now as a prisoner who is no longer in control of his fate and can only hope for help from the outside. In a desperate act, McCandless is forced to gather and eat roots and plants. He confuses similar plants and eats a poisonous one, falling sick as a result. Slowly dying, he continues to document his process of self-realization and accepts his fate, as he imagines his family for one last time. He writes a farewell to the world and crawls into his sleeping bag to die. Two weeks later, his body is found by moose hunters. Shortly afterwards, Carine returns her brother's ashes by airplane from Alaska back to Virginia, in her backpack.

Question: Why does McCandless stop riding on freight trains and go back to hitchhiking?
Answer: He was beaten by railroad cops.
Alternative answer: Because he is beaten by the railroad police