That's sad. Many big companies have something called diversity hiring where try would prefer hiring women over men but that only works if both are similarly skilled. But if as u say u are that skilled, so much so that the company would be at a loss not to hire u, they HAVE to go for u. If they didn't, it sucks. Can't say anything to comfort u honestly bcoz it's a shitty situation. But u are skilled enough that u can land an equally amazing job if not better. Don't be too discouraged.
My friend had a quite similar situation where he had his interview go really well with an automobile manufacturing company but they decided to hire a girl from our class instead who isn't as skilled as him just for diversity. But he didn't get discouraged and managed to land a similar paying opportunity(albeit in a completely different field).
So chin up and don't give up