Sword fighters are usually barely armoured and fight without shields to retain their mobility. Thus they can circulate around the immobile Phalanx formation and attack from the flanks.
During battle, Swordsmen deploy to the flanks, unless they are needed to fill the front battle line.