Rail travellers in the north of Scotland have been hit by serious disruption after a train derailed overnight.