That is not how it works though, as that assumes there is always a singular 'best' for a job and that is just not the case.
For instances a goal of a job can absolutely rightly be to broaden the experiences within the company to include groups not represented prior. So a marketing company in the 50's who has a broad business selling across all segments might decide THEY would benefit from having more qualified women on their team instead of just the 50 white guys they currently have. What that DOES NOT mean, is that as they go out and seek qualified women candidates only, that those women are less qualified than any male candidate. It is likely there are numerous people with the qualifications and skill sets to do the job.
So for a company to go out and seek a woman as it will IMPROVE their business , by broadening the experiences of the team, is in no way something wrong to do.