A Canadian judge who asked a sexual assault complainant why she could not "keep your knees together" is resigning.