Track engineers carried out a safety inspection on the line 24 hours before a train derailed and injured more than 20 people.