There are two alternative solutions which seem to work.
I. Use xinput
command to disable the unwanted behavior, in this way:
Search for the name or numerical identifier of the device with the command xinput list
(in my case, the name was 'Logitech Optical USB Mouse' with id=8), then ask for the options available for the device with
xinput list-props ...
(replace ... with the name or the id of the device: in my case 'Logitech Optical USB Mouse' or 8), then (as root) give (from the terminal) the command xinput set-prop ... "libinput Button Scrolling Button" 0
(replace ... with the name or the id of the device: in my case 'Logitech Optical USB Mouse' or 8) to disable the scrolling behavior (attributing the button with number 0 means disabling the function).
The problem of this approach is that at each reboot or unplug/replug of the mouse the original behavior of the mouse is restored, and thus the command should be run again from the terminal.
This can be partially solved (only for the case of reboot) putting the command in Startup Applications in this way:
Open Startup Applications with the command gnome-session-properties
and add a new application (for example, named 'mouse middle button') containing the command xinput set-prop ... "libinput Button Scrolling Button" 0
(replace ... with the name or the id of the device: in my case 'Logitech Optical USB Mouse' or 8).
II. The alternative solution, which at the moment seems to solve all the problems, is to disable the scrolling behavior from xorg, going into the /usr/share/X11/xorg.conf.d
directory (the path could be different in your system) and (as root) editing the file 40-libinput.conf adding (inside the Section "InputClass" with Identifier "libinput pointer catchall") the two lines:
Option "ScrollMethod" "button"
Option "ScrollButton" "0"
I suggest you to make a backup of the file before editing it in such a way as to be able to easily recover in case of possible issues.
In my case, after editing, this section reads like this:
Section "InputClass"
Identifier "libinput pointer catchall"
MatchIsPointer "on"
MatchDevicePath "/dev/input/event*"
Option "ScrollMethod" "button"
Option "ScrollButton" "0"
Driver "libinput"
EndSection
Links:
How to make xinput settings persist after devices are unplugged, replugged, and after shutdown, restart, etc?
https://help.ubuntu.com/stable/ubuntu-help/startup-applications.html.en
https://www.reddit.com/r/hyprland/comments/1acqgnd/how_do_i_enable_a_scroll_button/