An apples to oranges comparison. Girls, like all children are forced to go to class, thus they naturally adapt (in this case they do so better than males), but choosing to join a club is an entirely different matter and takes into consideration far more than just the subject matter, namely personal enjoyment.
When you decide to engage in extra curricular activities ( what my original statement was referring to not the AP course ) you take into account all factors that affect your enjoyment including the prospect of being awkwardly hit on for being one of the only girls in the group. There is quite a bit of psychology around group dynamics involving a gender imbalance, and it rarely turns out well. Such pressures can be the tipping point that forces anyone out of an extracurricular program, not just women.
Imagine if you will, a scenario where you are given an opportunity to learn about a subject you truly love from one of the best experts in the field, but you would have to take the class with 10 of the most far right nut wingers imaginable. A classroom filled with Rush Limbaughs. Some would have the mental will power to ignore it and get some good out of the class and others will say hell no.
Granted that is an extreme example, but for a middle school or high school child who are not the most stable people to begin with they may choose to join their friend's clubs regardless of what they may truly enjoy and in the process find something different from STEM.