I am using a Wacaom pen and tablet (Intuos Pro) and maybe it's just the way I hold a pen (which I'm not going to change) but I quite frequently accidently hit the right-click button while painting which causes the 'brush' window to pop-up over my working area. This slows my process down and is quite annoying. However, I do use the right click fuction for coloring layers, stroking/filling paths, deleting, etc... So I don't want to disable the button itself, just the 'brush window shortcut' that is assigned to it when I'm on the canvas.
No way to turn it off, and I'd hate to lose that function anyway, so all you can do is work out the best (for you) method of closing the window. For me that would be touching down outside the document window. I did have a look at the Panel Menu shortcuts make sure, as best as I can, and I made an interesting discovery.
In the 26 years I have been using Photoshop, I did not realise that we can access individual Brush Groups via shortcut. I have tested it and you can't use Fuction keys. It lets you assign a function key with modifier, but it then doesn't work. I then tried Ctrl 1 and that worked fine. I will absolutely be using some of these moving forward.
For the sake of people new to this forum, I like to remind folk that we can save custom keyboard shortcuts to custom workspaces. So when I reassigned Ctrl 1 (Cmd 1) from view 100% to one of my Brush Groups that only works in my default custom workspace, and I reach and use the default shortcuts by switching to anyother workspace. (I do this via actions triggered by shortcuts, and you _can_ use Function keys without modifiers to run an action).