For sexual harassment victims who are caught in the middle of a threatening or painful work situation, quitting makes sense. It removes them from the painful situation, allows them to move forward, and gives them a fresh start somewhere else. If you want to hold your harasser accountable, however, you can't quit.
If you just want to wash your hands of the situation, quitting is a viable option...but if you want to make sure the offender won't be able to mistreat anyone else in the office, then you may need to "work undercover."
Here is the top reason you want to put off quitting as late as possible:
It Puts You in a Weak Bargaining Position
As soon as you quit, you've given up your ability to negotiate a departure package for when you do leave. When you stay at the workplace, you're still a legal liability for the company. The moment you leave, that stops being the case—which means they're far less likely to take you seriously as a threat.
Unless you were the victim of extreme sexual harassment (e.g. assault), it'll be hard to build a harassment case for a previous employer. In some cases, you may be able to argue that your resignation was practically forced due to intolerable work conditions, which the law equates with being fired. However, that argument is not nearly as strong as staying with the company and engaging in "protected activity," which includes reporting harassment.
If you're fired and you have a documented history of reporting sexual harassment, your case will be far stronger than if you quit. It's far easier to build a case (or settle one) with an employer who still has you on the payroll or has fired you themselves.