Traveling by train in Europe is generally safe, provided you take the same precautions you would take when traveling through any unfamiliar place.
Tourists are easy targets—they're busy sightseeing or simply trying to make sense of signs in other languages—so it makes sense that there are so many stories of people getting pickpocketed while traveling. There are absolutely some things you can do to make yourself a less appealing target without sacrificing your trip altogether.
Here are a few pieces of advice to keep you and your belongings safe.
Before you leave home, make a photocopy of all important documents, including your passport, ID cards, traveler's checks, credit cards (both sides), insurance cards, and rail pass. Store the copies in a safe place that is separate from the originals. These will be immensely helpful if any of the originals are lost or stolen.
Keep all of your important documents (passport, rail pass, traveler's checks, credit cards) in a money-belt worn underneath your clothing. Reserve a small amount of cash—just what you will need during the trip - in an accessible pocket, wallet, or purse. Keep the rest in the money belt as well.
Stow your bags within sight whenever possible—in the overhead rack opposite your seat so you can keep an eye on it, or in between seats if they are positioned back-to-back. Keep your valuables in a smaller backpack or daypack that you can keep with you either at your feet or in your lap. Don't leave any of your bags or belongings unattended.
Bring along a few carabiners in order to strap your bag to a luggage rack, seat, or bunk in a sleeping compartment. The inability to make a quick grab-and-go will discourage most thieves.
When sleeping in a regular train seat, use your backpack or daypack as a pillow if you can, and store all important documents in your money belt.
On trains with compartments, board early so you get your pick of compartments—either one that's unoccupied or one that's got a few people who make you feel comfortable. If you feel uncomfortable for any reason, move on—or be prepared to switch compartments later.
When traveling on an overnight train in a sleeping compartment, always lock the cabin door from the inside before you go to sleep. These locks typically can't be opened from the outside, except with a special key the train staff have. (Some locks can't be opened from the outside, period.) If you're sharing a compartment with others, stress the importance of keeping the door locked.
Always double-check around your seat or compartment before you get off the train to make sure you didn't leave anything behind.
Be on the alert for anything that seems out of the ordinary. A commotion can often be meant to distract tourists in one direction so another member of the “team” can pick a pocket or two from another direction. If something feels strange, make sure you're not focusing so much on the commotion that you lose track of your surroundings.
Never leave your bags unattended in train stations (unless you're depositing them at a luggage storage office). Travelers are often distracted by trying to find a platform or looking for their train information on an overhead board, so it can be easy for pickpockets to swipe something if you're not staying alert. Also note that unattended bags are seen as a security risk.