I haven't used it, but it looks like you can change DPI with the razor-cli
command.
https://github.com/lolei/razer-cli
Says it can also print the current DPI, so I imagine that it'd be pretty straightforward to do a shell script of maybe three lines or so that cycles resolution through your favored resolutions when invoked. Doesn't show an example of the exact output of the command, though, so I can't tell you exactly what to run.
Looks like you can also set the LED color, if you want to have it indicate the DPI or something.
If you can't figure out the script but can paste the exact output from the command printing the current DPI, I can probably help you with the script.
I use Sway, and Sway can be configured to invoke commands when a button or key or whatever is pressed, so you'd just have it run said script.
https://man.archlinux.org/man/sway.5.en
You don't say what desktop environment you're using. If you're using Gnome or KDE, I expect that there's some similar utility, probably built into the desktop environment, to bind mouse buttons to invoke commands.