If women are paid less for the same work, why don't employers hire just women? If women are paid less for the same work, why don't employers hire just women? Do employers decide to lose profits just out of sexism, in feminists' and researchers' opinion? It doesn't make sense to me. In the free and competitive market, if people earn less, it means they generate, or are expected to generate, less added value (for example, because they are less educated). Am I wrong?
There could be several reasons here are just few:

Principal-agent problems. Firms are typically not managed by their owners but by managers (agents) who act on the behalf of owners/shareholders (principals). While, owners might desire to maximize profits agents can to some degree act to pursue their own goals (see discussion in Hendrikse Economics and Management of Organizations).
For example, CEO might spend more lavishly on things like their private jet, limo, having HQ built by famous architect than profit maximizing CEO would. In the same way CEO/manager with taste for discrimination might pursue that taste even at the expense of profit (to a degree of course).

Consumers could have taste for discrimination. This is in fact classic example coming from one of the earliest work on discrimination. If consumers simply have preference for seeing men instead of women at some work and are willing to pay for satisfying this preference, there will be wage gap between men and women (see Mankiw Principles of Economics pp 395).
Mankiw has a good example of this for the race wage gap, but the logic of the example directly extends to gender wage gap:

Studies of sports teams suggest that racial discrimination has, in fact, been common and that much of the blame lies with customers. One study, published in the
Journal of Labor Economics in 1988, examined the salaries of basketball players and
found that black players earned 20 percent less than white players of comparable
ability. The study also found that attendance at basketball games was larger for
teams with a greater proportion of white players. One interpretation of these facts
is that, at least at the time of the study, customer discrimination made black players
less profitable than white players for team owners. In the presence of such customer discrimination, a discriminatory wage gap can persist, even if team owners
care only about profit.


It could be result of government intervention (See discussion in Mankiw Principles of Economics pp 395).
For example, many governments around the world mandate that firms have to provide women with job guarantee during late pregnancy/mothers leave. Perks like these are costly and in competitive markets firms will just pass costs of these perks directly on their female employees (in form of lower wage - although this would not affect total compensation it is part of explanation for wage differentials).

Most labor markets are not perfect. In imperfect labor markets there are often quasi-rents to have that can be split between employee and employer. If for example women tend to be less assertive during negotiation (e.g. see Amanatullah &amp; Morris, 2010), they might end up with less quasi-rents than their male counterparts (this argument is covered in greater detail in the Papayapap's answer).


The list above is not exclusive, but those are one of the major reasons you will commonly find in economics textbooks.
To sum it up, the argument you make in the question is valid argument but it  is only guaranteed to work under host of additional supporting assumptions. For example, assumption that customers do not care about gender might be true in some profession but not in others (e.g. perhaps male anchor appears more trustworthy to audience?).
Although careful studies that control for all relevant characteristics show that gender wage gap is much smaller than laymen commonly perceive it to be, based on senseless comparison of aggregates between male and female pay, many studies show that there still is some gender pay gap that cannot be accounted for by objective factors. See discussion of these results in this nice explainer from The Economist. For example, in 2016 the gender pay gap in the UK was estimated to be only $0.8\%$, in France$2.7\%$ and Germany $3\%$, once objective factors were accounted for. That is admittedly small, but should not be trivialized nonetheless.