It is a business.That's pretty thoughtcrime-y. That's like convicting a recovering alcoholic of drunk driving for not going to the bar because they know they'd get drunk and drive home if they went there.
If the courts did say it was illegal to fire her then it means the business would be basically immune from sexual discrimination and harassment in the future. It would be a very easy case: "We tried to fix the situation before the harassment took place but the supreme court forced us not to, and here is the proof." All three courts realized just how insane that would have been.
Admitting to intending to sexual harass someone should be a crime in and onto itself. It's like planning to swindle someone or worse.
It is not so different from if a business owner who sees a high risk of "employee dishonesty" (theft) and then fires an otherwise good worker merely on suspicious behavior without actual proof.
Or a business owner who can see that certain employees are a high risk for damaging goods, and then firing them.
Or a bar owner who stops serving drinks to somebody when they look drunk. (In many places this is mandated by law, it is such a high legal risk.)
Business owner sees a very legitimate legal concern (high probability of a sex-related infraction) and takes action to avoid the legal problem.
As the defense pointed out, and all three levels of the courts pointed out, this is an entirely legitimate business move. It has happened many times, gone through the courts many times, and repeatedly seen to be a perfectly legal business decision. They see a legitimate risk, and they take steps to manage the risk. It is not discrimination.