First, you have to purchase the "Counter Attack" upgrade for Monkey. It can be found under the Combat sub-menu of Upgrades.
Next, whenever you're in combat with mechs, hold R2 to have Monkey block, and press Circle right when their attack is blocked to perform a counter attack. You'll know it's done right when Monkey does a sort of flipping move and the mech is stunned.
It takes a bit of practice to get the timing down, but once you have it, performing 20 counter attacks is no problem.