Hi and welcome Zanar,
Unfortunately, to allow phalanxes to be effective in sieges, you have to change their formation. To do this simply right click and drag the mouse till the unit is long, thin and, most importantly, is able to easily fit through the streets perfectly with few gaps either side, let go and your unit is in a new ranking formation. At any point in the almighty siege you can do this to make sure that your unit has no flanks and, any unit that wants to attack it, has to face the epic frontal spears that nothing can break through. Hope this helps you, cheers!