I believe the button codes are configured by the x input driver that controls it, either the old mouse
driver, or, in most distros these days, evdev
There is a standard for input
devices that's supposed to ensure that the basic buttons at least are always configured the same. But I believe there are quite a few oddball devices out there, especially among the cheap stuff, that while supposedly conforming to standards, in fact don't quite do what you expect them to. You seem to have found one of those.