How to change the order of the virtual desktops
This occurs when the Mac fails to recognise the displays correctly. At reconnect, it 'forgets' what physical order you had them in.
One of the users on Ask Different made an app to keep a tighter hold on this - which I'm afraid I've been unable to track down. I hope they find this question &amp; leave us a link to their app again.
In the meantime, a workaround would be to re-arrange your display order in System Pref &gt; Displays &gt; Arrangement.
You can drag individual displays into whichever order you would prefer.
If you click &amp; hold any display it will highlight in red - on the control panel &amp; also right round the display that is referenced, so you can easily tell which is which. The primary display is the one with the menu bar [which can also be moved, if needed]
Image showing 3 monitors, centre highlighted, primary assigned to left-most.

If your Mac is suffering from this 'forgetfulness' you may need to re-do this each time you change your connected monitors [hence the need for the app mentioned above.]
I'm assuming this is not actually the same as How to prevent Mac from changing the order of Desktops/Spaces which is actually a different issue with a simple fix in prefs.