If your employer has instructed you to participate in a workplace investigation, then yes, you need to participate. Disobeying that directive would be just like disobeying another instruction from an employer, and can come with disciplinary consequences. Remember though, if you have been accused of something, that simply participating in an investigation is not an automatic finding of guilt. The investigator is neutral, and is there to get your side of the story as well.
If you have been named as part of an investigation then fear of participating may be incredibly stressful, and you might think it is better to try and take a leave, or to resign immediately. While a resignation would stop an investigation in a non-harassment scenario, it would not stop a harassment investigation – it will still continue in your absence. If you have been accused of harassment, then resigning before any conclusions are drawn is often a poor decision. A resignation will also not stop any criminal charges, if they result from the findings. If you are off on a medical leave or a job-protected leave, the investigation will likely be at a standstill until your return, but it will be waiting for you when you are back at work.