We tend to assume that contact forces act as though they are concentrated at the centre of the area of contact, perhaps because we can treat the gravitational force on an object as though it is concentrated at the centre of mass. This assumption for the contact forces is not always correct, but it often goes unnoticed when the assumption does not apply. This is one situation when the assumption is not correct.
In diagram (a) there is no net force on block A. However, if the applied force $F$ and the normal force $N$ both act through the centre of block A, then you are correct in deducing that there is a net torque, so the block should rotate anti-clockwise.

Either $F$ or $N$ or both must be offset from the centre - as in diagram (b) - in order to create a clockwise counter-torque, thus keeping the block in equilibrium. You have perhaps noticed when performing this trick with blocks that if you apply the force $F$ too far down then block A does rotate anti-clockwise. And conversely if you apply $F$ too far up then it rotates clockwise.
The centre of force does not have to be the same as the centre of area. The contact force is the result of a contact pressure across the area of contact between two solid surfaces. This pressure does not have to be distributed uniformly. In many situations such as this one, in which toppling or turning is about to occur, the contact pressure increases toward the pivot point. See How is normal force distributed along the surface of contact?