This can happen if you apply too much brakes too quickly or just apply lots of brakes in general. Having unfitted wagons also increase the chance of derailing cuz when you heavy brake, it causes the freight cars to crash into each other and derail. They are working on updating the physics to decrease derail, but not completely. I have this issue too. Affects every platform.