It is called ‘backing’. It is so that the dog can get to the front of the mob in yards to make sure the ones in front keep moving so that the ones in the middle don’t get crushed by the ones coming from behind.
The front sheep will often stop at a gate and won’t be worried by the noise coming from behind them (often during shearing there will be noise in front of them as well from the shed making them reluctant to keep moving).

The ones in the middle have no where to go and the ones behind would smoother them if the dog just kept working on the back few to try and keep them moving.In other words, the dog is saving the middle sheep from being smushed by their peers by running along their backs and keeping the ones at the front moving.