If your /whois is done inside the ON JOIN event, the /whois reply comes before the op is given their OP status, but the resulting ban comes after they've been given OP status.

If you're trying to prevent spammers, it's possible for someone to blurt out their spam before the ban takes effect. One method some channels do is to make the channel +m moderated, then give everyone voice except the spammers.

You'll probably want to give OP based on address mask, instead of nick. Anyone could use a non-registered nick, and even a registered nick for the few seconds needed to join a channel. It's harder for them to be ident@*.some-ISP.com