"The market" is not some all-powerful, benevolent force that will always achieve the best outcome for humanity or society as a whole. Markets are disproportionately controlled by the current holders of wealth (and therefore power), who will naturally tend to seek their own advantage at the expense of others. And so some kinds of regulation are often appropriate to protect the less powerful participants.