I think when trains reached JP ,existing loco was attached in other end .Detached engine was kept waiting when next train arrived .
So station staff must have planned something like this .
I have seen in BZA during Loco reversal for trains coming from VSkp side or Kazipet side .it happens like this .different loco gets attached