I have a mid-2014 15-inch MacBook Pro (the one with the Retina display) with macOS 10.12.6. I use spaces a lot and normally have my most-used apps open in specific spaces. One of these is Safari, which is set to always open in space 2 (out of 5). However, I often move Safari windows to different spaces as needed (for instance, if I'm going to use a website for reference while using an app that runs on space 4, I'll move the window with that website to space 4).
I tend to leave Safari open when I turn my computer off; that way, I get back any windows and tabs which I was using in my last session and am likely to use again in my next session. However, when the computer starts up, sometimes some of the windows which were in different spaces go back to space 2. It doesn't happen always, and when it happens it only happens with some windows (so, for example, the window on space 1 will remain there but the windows on spaces 3-5 will have migrated to space 2).
(I know that quitting Safari and reopening it causes all windows to go to the space where it's opened or where it's told to open in. I'm talking about Safari restarting by itself again after I've shut down or restarted the computer without having quit Safari, which normally puts windows in the spaces they were in before the computer was shut down or restarted.)
Does anyone know why this happens?