I can't offer a solution, but rather an explanation and some workarounds.
This problem is caused because window positions are stored as positive coordinates from the top-left display.
The software doesn't consider any of your monitors to be "secondary", but the top-left display is kind of "primary" because its top-left corner is used as the origin for window coordinates.
When you add or remove a display (by connecting/disconnecting it or turning it on/off) above or to the left of your laptop screen you are changing the origin of the window coordinate system and this will cause all your windows to move because in Ubuntu, sadly, the windows retain their absolute top-left coordinates regardless of display changes.
Rather than having to move your windows before you connect/disconnect your external display, you can find them afterwards by pressing Super+S to show your workspaces. This is slightly less annoying.
Instead of aligning your external monitor to the left (which causes the coordinate system origin to move and the windows to change screen) you could keep it physically to the left, but aligned below in the display settings. This is still "wrong" but I find it less mentally jarring to have the "secondary" screen considered "below" than in the opposite direction to where it physically is.
Hopefully in the future there will be a fix to ensure windows' positions are updated during a display change so that they remain on the same physical display afterwards.