Insurance companies have a strong incentive to price policies accurately, so you have to assume that discriminatory decisions are made with that goal in mind. Any restriction on factors that make the model less accurate (like forbidding race) will lead to higher volatility and a lower stock price (insurance companies are prized in portfolio management for their low volatility).
The government, however, recognizes that most people are forced to buy car insurance, which means that they are being forced to pay for those profit-maximizing decisions. And to the extent that being forced to pay can creates a downward spiral of high costs leading to poor decision making and even higher costs, that is something to be prevented.
So where to draw the line? Well, the people most at risk of getting into a downward spiral are the already economically disadvantaged (read:poor). The government already prevents considering whether the insured is poor (either explicitly or implicitly by not allowing questions about income/net worth on applications).
But really, any factor which would tend to disproportionately target the already-poor would need to be limited as well, since that can often become an end-run around the limitation. If you consider the factors that would do that at the population level, race would be very strong indicator of income, but gender would not be. (yes, I know women make less in the same jobs, but we're talking about the macro here, including women who are heads of household, 2-income families, and stay-at-home moms).
Now, it doesn't explain why other factors that would seem to be associated with low income like zipcode are allowed. But to answer your question about why gender is ok to price discriminate against while race is not, I think the answer is we try not to force poor people to pay more for government-mandated things just because they are poor or otherwise exhibit a feature that would characterize them that way to an uninformed observer.