How can I force the mouse cursor to stay in the window of another game, when XCOM / XCOM 2 is running in the background?
Rather than addressing the issue with XCOM directly, I suggest an indirect solution using window management software.
I have been using DisplayFusion to manage my windows and mouse cursor for many years, and although I haven't used it myself, there is a feature that lets you lock your cursor to the current monitor or active window by pressing a hotkey. See the screenshot below:
DisplayFusion has a basic free mode, but also has a 30 day trial for Pro, so you can test both of these functions and see if it works before buying. Hope that helps!