There are way more details to the AB testing over. UX is just a percentage of the total product. Users are being subjects because their behavior is what you make money out of. Is it moral that's a different discussion.
Optimizing to the detriment of the user (eg for engagement, conversion, whatever) is straight malevolent and I've yet to run across a moral justification for it apart from market nihilism.