Answer
(Fatwa: 649/606/N=1433)
Before starting salah in train one should fix the direction of qiblah by compass (qiblah numa) or by any other source and then if you know during salah that the train diverted then you can turn towards qiblah, but if it is not known then in case one is totally diverted from the qiblah direction then too salah shall be valid. There is no need to reoffer it. (Baqiyat Fatawa Rashidiya p 154)
Allah (Subhana Wa Ta’ala) knows Best
Darul Ifta,
Darul Uloom Deoband