the problem is that 'if ($banmask iswm $ialchan($ulist(*,100,%?),#,1))' is only checking the banmask against the first matching address in the channel, when there could of course be several matching addresses.
the overall method, "for each level 100 address, check if it matches a user in the channel who is affected by the ban", is not efficient in general. a better method can be described as "for each person affected by the ban, check if they are matched by any level 100 address":
on @*:ban:#:{
var %i = 1
while ($ialchan($banmask, #, %i)) {
if ($ulist($v1, 100, 1)) {
mode # -b $banmask
return
}
inc %i
}
}