Mouse confined to main screen while tabbed out

I have had issues with this in the past, and I have finally found the way to reproduce this.

This issue occurs when I tab out immediately after quitting the score screen after a match without waiting for the main menu to load.

The game will not be in the foreground, but the mouse cursor will still be confined to the main screen where the game is opened until I tab to something else.