It is possible you were unfairly rejected. This is not really possible to prove one way or the other, from the information in your post.
Unrelated to that, however, your post shows a lack of understanding for the standard justifications of affirmative action, and why admissions committees sometimes may try to improve the gender balance of their decisions. I would recommed that, regardless of your opinion, you take the time to understand their point of view.
The executive summary of that point of view is that they do not believe they are giving an unfair advantage to women and minority candidates, but rather they believe they are correcting for an unfair advantage that majority (male, white, etc.) candidates already have, that is not always easily measurable.
Once again, you are free to disagree, but you should understand it.
With that in mind, let me present the standard responses to your complaints, from the admissions committees' likely point of view.
Aren't the actions of these admissions committee members jeopardizing the output of their math department by choosing less capable people?
No, because they do not believe they are choosing less capable people. It has been shown in a variety of studies that people (including admissions committees) are implicitly biased against women and minorities. That is, given a female student and a male student (alternatively: a student with a female name and a student with a male name) with the exact same level of ability, people routinely underestimate the female student's ability in STEM compared to the male student's ability.
The admissions committees are trying to correct for that, so it is unsurprising that they choose to admit candidates who you perceive as being less capable and prepared. However, the committee does not see it that way; they think the female students are equally capable and prepared, but are unfairly discriminated against.
Moreover, who is right (you or the admissions committees) is actually an empirical question: are the students they are admitting actually less qualified, or are they actually equally qualified? In theory, given the time to make well-controlled studies and the ability to collect infinite amounts of data, we could resolve this question one way or the other. And there has been a lot of research on it already, although none of it is completely conclusive, and the world is constantly changing, so it is unclear to what extent the past studies apply to today.
Furthermore, in my school, some of the incoming female PHD students know less math (insufficient preparation) than a typical junior/senior undergraduates, which supports my theory.
What makes you believe these students are not as strong? Once again there is a possibility of implicit bias here, since women are often underestimated by their peers. Few people have the capability to act as a "neutral party" and judge someone else independently of whether they look like them, talk like them, or share their personality type. You should consider whether, one way or another, you are biased in some way in your evaluation.
I sincerely do believe my profile is stronger (see comparison below)
I'm not entirely convinced by your comparison. The coursework and grades don't matter too much; the GRE matters a little more, but not a lot. The REU experience does matter. However, we don't have access to the recommendation letters or cover letters, so it's possible that hers were a lot stronger.
Moreover, from the admission committees' likely perspective, your entire comparison is predicated on the idea that you and your girlfriend were given the same opportunity to succeed, and this seems unlikely. Although you are in the same department, men are more often participating in mathematical activites throughout high school and college; this includes, for instance, applying to REUs more often. Supposing that your girlfriend is equally qualified to you, it would be unsurprising (to the committees) that she applied to and participated in fewer REUs.
The admissions committee is likely interested in assessing, not just "how much stuff does this person have on their resume?" but also, "how likely are they to succeed in our program?" And the latter question is, while a lot more difficult to evaluate, clearly more important. From their perspective, they might believe that women have an unfair disadvantage on average when it comes to their resumes, even though they are still likely to succeed given some solid evidence (e.g., prior research experience and solid coursework).
Another way of saying this is that more things padding your resume is not necessarily better than fewer things, which nevertheless point strongly to the candidate being highly qualified.
Shouldn't admission decisions be based on "who is best fit and capable to be doing math research" instead of "who will look best for our department"?
Yes, and the admissions committees believe they are selecting for the former, whereas you believe they are selecting for the latter. They believe that women are underselected and underrepresented despite being highly fit and capable.