I had a similar issue with this, on Windows 11 Pro Insider Preview, v 23493.1000.
I installed the Win11 preview because I wanted to disable Taskbar Window Grouping.
Turns out, in Windows 11, clicking (a pinned) window on the Taskbar several times, now toggles between the window being visible or sent to the background.
In my case, this annoyed me every time when an old version of an application (WinSCP 5) would pop up an alert Msgbox from its own application, which I would assume included code to set focus to that popup box.
Windows 11 would interpret that application as receiving another setfocus event, and thereby actually sent the whole application to back, effectively pulling the focus "away" from the app, and ended up showing the app I had open prior to my app.
In my case, updating WinSCP to version 6 (which included Windows 11 flat style graphics) seemed to fix the issue... for this app...