If you order them to stop (backspace key) immediately before ordering them to use phalanx formation, they usually manage to put down the pikes and then adjust their formation. This is not a guaranteed thing though.