Thanks for clarifying why and when this happens. I have googled the problem 10+ times with many different wordings.
It feels like Opera just sends the active window back randomly.
I've had this problem for a while now on Monterey / Opera (always latest versions). It makes Opera very hard to use with multiple windows.
There's also another problem with Opera's window handling that amplifies the problem further: Opera doesn't support "command-drag to move an unfocused window, keeping it behind other windows".