If a company never hires women it's pretty easy to catch them in a sting where you send two more or less identical CVs, one with a woman's name and one with a man's. If the women's is rejected and the man gets an interview it's lawsuit time.
It doesn't really work that way in the real world. You can certainly embarrass a company that way, and it makes for a good "report" to release to the media. But you're not going to be able to build a lawsuit on a "sting", since you have to show actual harm. You can't sue over a job you never intended to take. Well, you can sue over anything, but you won't win.
The only way to avoid being sued for discrimination is to stop discriminating, not to do more of it.
The system can't be perceived by managers as capricious. If hiring women exposes you to more legal risk than not hiring them, and you don't think you can mitigate that risk, you don't hire women. Or rather you hire only enough women that it's not obvious you're deliberately not hiring women.