The Loco detached from front & attached to rear (as the train needs to run in reversed/opposite direction from that station onward)!!
In some case, the loco detached & loco attached @ rear may differ (not same), in case like Diesel to Electric (& vice-versa) or to minimize TAT (turn around time)