Your assumption that $F_{AB}=-F_{CD}$ is incorrect.

Your mistake is that the magnetic field is proportional to $z$, which is +ve above the xy plane and -ve below it. So the $B$ field points in the +x direction at AB and in the -x direction at CD. The current is also in the opposite directions in AB and CD. So because both magnetic field and current are in opposite directions the force on AB and CD is in the same direction : (-) x (-) = (+).

If the magnetic field had been in the same direction at AB and CD, as is the case for a uniform magnetic field, or if eg $B(z)=k|z|\hat{x}$, then your assumption would be correct.

Your mistake is that the magnetic field is proportional to $z$, which is +ve above the xy plane and -ve below it. So the $B$ field points in the +x direction at AB and in the -x direction at CD. The current is also in the opposite directions in AB and CD. So because both magnetic field and current are in opposite directions the force on AB and CD is in the same direction : (-) x (-) = (+).

If the magnetic field had been in the same direction at AB and CD, as is the case for a uniform magnetic field, or if eg $B(z)=k|z|\hat{x}$, then your assumption would be correct.

edited Mar 9 by sammy gerbil