In case of medicine - because it's a large field full of career paths that are very different from each other. The daily realities of being a pediatrician, a surgeon, a psychiatrist or a radiologist have very little in common.
There's this hypothesis that men statistically tend to pick jobs involving working with and treating patients as things, and women tend to pick jobs involving people and socializing. Medicine as a field is full of high-status jobs of both kind, so - under this hypothesis - gender parity of the overarching field is entirely unsurprising. And, as predicted, individual specializations tend to show strong gender skew.
Law is also a very large field, so I suspect the profession probably shows a similar dynamic.
Viewed through this lens, our industry is less like "medicine", and more like "radiology". And I suspect - but didn't check - that if you expand the definition of "software" to include supporting fields like design, UX and testing, the overall gender ratio will be much closer to 1:1.