Because more people will see them and they’re kind of iconic, so they’re a fun target for graffiti. People don’t really vandalize other people’s personal cars unless they have a grudge or they’re trying to break in to steal something. It’s kind of a jerk move.
They’re also parked overnight in more remote areas than most cars. In fairness if you parked your car in an industrial area near a train yard overnight it’s probably more likely to get broken into than on a residential street.
It doesn’t matter which is a bigger target, it’s whether trains are a target at all. Vandalism definitely impacts cars; there are lots of issues with broken glass in cities around the world. Sometimes from a random person just smashing every car on the block, or for theft.
But trains are definitely a big target, given you’ll find them all sitting outside overnight in a remote lot which might not be protected very well.