The thing that controls this is the hot_exit
setting, which is enabled by default and which does all of this out of the box in a global sense. That is, by default you can exit Sublime and restart it and get back to exactly where you were.
If you’re on MacOS, it may be worth pointing out that closing windows and quitting the application aren’t the same thing; to get this to work you need to actually quit Sublime.
On a window by window basis you can do this by using projects in Sublime; the state of windows that have a project open in them are persisted in workspace files specific to the project, while the application state as a whole goes into an overall session file.
So by default quitting Sublime will allow you to restore back to where you were last on restart, but if you want to close a window and then recall it’s contents later (without quitting Sublime in the interim) use projects.