A unit must immediately make a Panic test if a friendly unit moves through it whilst fleeing or falling back in good order. For simplicity, resolve the movement of the fleeing unit before making and resolving the Panic test.
A unit that fails a Panic test after being fled through will flee directly away from the nearest enemy unit which is not itself fleeing.
Note that this can prove the most destructive form of panic, as one unit can panic and flee through another unit, which in turn might panic and flee through a further unit, and so on until your battle line is in total disarray.