The behavior you describe happens if Form1's window is set as the owner window (in Win32 API terms, not VCL terms) of Form2's window. A window cannot go behind its owner.
You can use GetParent() or GetWindow() to determine a window's owner.
In the first example, you can freely switch between Form1 and Form2 only if Form1 is not the owner of Form2. SetWindowPos() DOES NOT change window ownership! That can only be done with CreateWindow/Ex() when creating a new window, or with SetParent() or SetWindowLongPtr() on an existing window.
How a TForm determines which owner to use when creating its window is a bit complex (there are other conditions that can affect the following, but this is the basics - see the source code for TCustomForrm.CreateParams() if you want to see the full logic) :
If a TForm's PopupMode is pmNone (the default), then:
if Application.MainFormOnTaskBar is true, the Application.MainForm window will be the owner.
unless there is no MainForm, or Application.MainFormOnTaskBar is false, then the Application window will be the owner.
If a TForm's PopupMode is pmAuto, then:
the currently active TForm window will be the owner,
unless there is no active TForm, or its window is currently minimized or hidden, then
the Application.MainForm window will be the owner,
unless there is no MainForm, or Application.MainFormOnTaskBar is false, then the Application window will be the owner.
If a TForm's PopupMode is pmExplicit, then:
the PopupParent window will be the owner,
unless there is no PopupParent, then
the Application.MainForm window will be the owner,
unless there is no MainForm, then the Application window will be the owner.