I'm not sure about the UK but law and medicine in the US used affirmative action to address sexism in the profession.
There were class action lawsuits that required law firms, law schools, medical schools, and hospitals to accept women doctors and lawyers. After sexism was recognized as a problem law schools used affirmative action to admit gender-balanced classes and law firms hired equal numbers of men and women.
STEM subjects didn't have these interventions so it's unsurprising that sexism is more of an issue than in other fields.