Why is WordPress wrapping search for users that looks like integers with asterisks and how do I fix it?

The search term was getting surrounded by asterisks.

Yes, and they are wildcard characters, and in the case of the Users list table at wp-admin/users.php, those asterisks are being added by wp-admin/includes/class-wp-users-list-table.php (see source on GitHub for WordPress v6.1), so that a LIKE '%<keyword>%' query is performed by default.

So to fix the issue, yes, I’d also use trim( $search, '*' ). But you can also use the raw search keyword, e.g. using $_REQUEST['s'].