فَإِذَا رَفَعَ رَأْسَهُ مِنَ السَّجْدَةِ الثَّانِيَةِ مَضَتْ هَذِهِ الطَّائِفَةُ إِلَى وَجْهِ الْعَدُوِّ
Translation: When the imam raises his head from the second prostration, this group goes toward the enemy.
After the second prostration the first group leaves the imam and returns to its guard position. Its own prayer remains incomplete and will be finished later.
The shift occurs after both prostrations, not after only the bowing or first prostration.