Can't recall the particular shot, but the effect is commonly created using multiple composite layers
Typically there will be three layers
- the person walking in real time,
- the person in slow time,
- the background
Each is filmed separately as individual layers.
For the "people" layers only the people (and I guess the punchbag in this case) are used - the rest of the layer is transparent.
Now in editing a composite is done with the background layer, then the Buffy layer, then the Giles layer. When Giles moves behind Buffy the editor simply swaps over the order of those two layers at that point. So
- Background > Buffy > Giles
- Background > Giles > Buffy
The result is that they then appear behind.
Filming wise this probably means that both actors were acting in front of a chromakey (green) screen. Also if the camera was moving in the shot then a motion controlled camera is likely to ensure that each element of the composite was filmed from the same angle throughout the shot.