System Settings/Preferences > Search for "Spaces" > Uncheck Automatically rearrange Spaces based on most recent use
Newer MacOS Ventura (v13)
System Settings > Desktop & Dock > Scroll down to Mission Control section > Uncheck Automatically rearrange Spaces based on most recent use
Older macOS (v12 and older)
System Preferences > Mission Control
Uncheck Automatically rearrange Spaces based on most recent use.
This will fix the order of all your regular Spaces - but not Fullscreen spaces, which always go to the right of existing numbered Spaces.
From comments: Note this cannot fix the Mac confusing which external screen is which. That's not user-controlled at all, & seems to occur mainly [though not always] when the external screens are identical.
This echoes the behaviour of Cmd/Tab or equivalent in most operating systems, so could be considered a 'sensible' default.
just to save this attracting even more comments on why it was a good/bad choice of default.