It’s legal because it’s not done, thankfully. The second it appears in birth gender statistics, it would become illegal, just as it is in, for example, India.
You don't know that it isn't done.
https://en.wikipedia.org/wiki/Sex-selective_abortion#United_...
Those who strongly favor male offspring may be a small minority. Even without intervention, there will be more male births. That ratio differs geographically. It would take a lot of sex-selective abortions to show a clear correlation.