So the phalanx becomes resistant to cavalry because of its loose formation

?
That's worth trying (remember to make the pikemen resource size 2 and to lower their food consumption by 1 unit) but has a lot of other clumsy effects.
The ideal solution would be to give pikes and some other weapons an anti-cavalry identifier with the following game mechanics:
* Ignores the defense bonus for mounted units.
* Repel attacks against mounted units inflict full damage, *and* gain a charge bonus to damage based on the attacking mounted unit's AP.
That'd give the heavy cavalry serious second thoughts about charging a pike square, and would also encourage tight formations of pike squares (for more attacks.)