First, banned user ids are fetched. Then all affected user rows are fetched and each row is checked whether the user is banned. Also, $user['user_type'] == USER_IGNORE rows are skipped.
a) Do not fetch users who are banned from the database. An array_diff() should do.
b) Do not fetch users with $user['user_type'] == USER_IGNORE. Either make sure such messages are never in the queue or ignore in the SQL query fetching users.