Username has already been taken

I’ve connected my AD server to Gitlab. User accounts are created on first logon.
For one user (let’s call him “foo”) an account called “foo1” is created. When I visit /admin/users/foo1 I see the user, but when I visit /admin/users/foo, I get a 404.
When I try to manually edit the username from foo1 to foo, Gitlab shows me an error: “Username has already been taken”.

When I run curl --silent --header "Private-Token: <removed>" 'https://<host>/api/v4/users?username=foo' ; echo, I get an empty array as result, but when I run curl --silent --header "Private-Token: <removed>" 'https://<host>/api/v4/users?username=foo1' ; echo, I can see the user.
So why does Gitlab think the user foo exists?