Maybe you are onto something there. It would be easier and safer to simply connect a long train of cars than it would be to avoid connection (Collision).
Another issue with a magnetic avoidance system - magnets are heavy and would be a fuel hungry solution, moving all that weight up hills or accelerating from a stop. also, if you've ever tried to push to repelling magnets together, especially strong ones, they tend to flip in your hand and connect N-S. Now imagine slamming on your brakes late as you approach the car ahead of you, the car dives, and is pulled under the magnet of the front car, then click - they are connected. Who carries the demagnetizer?