https://help.ubuntu.com/community/ManyButtonsMouseHowto#Remapping%20buttons documents how to remap the buttons on a mouse. To quote it:
Some pointing devices have a strange button mapping, so need some tweaking to match X's perception of things. Such tweaking can be performed at runtime with xinput - find your device in xinput list and run xinput set-button-map 1 2 3 6 7, replacing those numbers with your required button mapping. You might be able to find it by searching for other people with the same hardware, or you might need to play around and see what works.
Here is the xinput(1) manual page explanation of the --set-button-map option:
--set-button-map device map_button_1 [map_button_2 [...]]
Change the button mapping of device. The buttons are specified
in physical order (starting with button 1) and are mapped to
the logical button provided. 0 disables a button. The default
button mapping for a device is 1 2 3 4 5 6 etc.
This should allow you to re-map the middle mouse button so that it is properly detected as the middle mouse button.