Today I was listening to the latest episode of The Crossover podcast, and towards the end of it the guests were making a good point that sexism and other forms of discrimination are forms of bad habits, in that people need some amount of self-awareness in order to break out of. Without conscious self-critique, it's easy to fall into a type of confirmation bias or small sample-size false pattern (e.g. "Oh, all the women in this company are doing secretarial work, so that must be the type of work women are good at.")
In a way, it's deeply related to the difficulty of doing science--in particular, thinking of things statistically. Statistics is hard because it doesn't jive with the way we think. Humans fall to all sorts of fallacies because we don't understand probabilities, we often see patterns that aren't there, and we have trouble recognizing biases that exist in our circumstances. That all the women in one company work as secretaries doesn't mean that all women are secretaries any more than the fact that all past US Presidents being men mean that all past men are US Presidents, and yet we do have some confirmation bias to enforce the former beliefs.
Perhaps, then, one way to reduce sexism, racism, and other forms of prejudice and improve society at the same time is to teach everyone more science and statistics, so that they can learn to see such fallacies a bit better and be more resistant to false logic in all walks of life. Logic used to be a key part of a proper education, and I think it should be again, at least its successors, science, math, and statistics. Those, along with a respect for others that the humanities gives, should give us a good starting base for a more equal and fair society.