It was to run the loco round... only one loco (66743) was working the service - sometimes it's T'n'T I believe.
Platform 1 is the only platform of the two at the station with a headshunt/set of points into the adjacent ("West") sidings to release the loco and run it back round. So the Royal Scotsman arrived into P2 at 1528. The Elgin service arrived P1 at 1614 and left again at 1713, and once that was out of the way, the rather odd-looking ECS move above would've happened - i.e. 66743 will have reversed the stock out, run back in on P1; been released and used the headshunt to run back round the stock via the West Sidings.
66743 will then have taken the stock back out of P1 (this time being on the "front" as it left the station) then reversed back into P2 ready to leave in the morning to Boat of Garten.
The one bit I'm not sure about is why the Royal Scotsman didn't just use P1 in the first place and the Elgin service P2 (as came in after the Royal Scotsman) - but may be due to platform length (although they look similar length on Google maps) or some other operational reason. All normal service trains arrive/depart P1, so perhaps it's done so as not to disrupt the normal passengers/workings?
There's a
track diagram I found on line which helps show the set-up; it's hand-drawn and c.10 years old, but I doubt much has changed... You can also get a feel for the track layout on Google Maps satellite/street map views.