It is not clear to me if the issue is that when you disconnect from the docking station, all open windows collapse into one space on the laptop. Or that the windows do not go back to the correct spaces when you reconnect to the docking station. Perhaps it is both. Any suggestions would depend on which it is.
And is it related to or a continuation of this thread:
If so, it seems that window managers have not given the result you desire?
One thing you can try (and may already have, based on the prior thread) is to assign applications to specific spaces.