The stolen items -- mobiles, pen drives, and Rs 2,400 in cash -- were recovered from them, the official said.
The two work for a company contracted by the railways to do construction work.
"They have confessed to the crime," an official said, adding that the search is on for three more accused, who are are absconding.
The five-member gang allegedly looted cash and valuables from people in a Delhi-Saharanpur passenger train between Khandrawli and Kandhla railway stations in Shamli district on the intervening night of Wednesday and Thursday last week.