No it’s not. It’s illegal to discriminate based on that consideration. It’s not illegal to take someone’s race, sexuality, or any other protected class into consideration.
When you hire a man, it’s not like you don’t know they’re a man. The issue would be if you ONLY hire men (intentionally or not).