A major train derailment occurred in New South Wales just after safety concerns were raised by the rail union.