unlocking laptop moves all windows to primary display
It does it because the external display isn't waking up fast enough to register with the Mac. 

Not sure there's any way to fix that unless you can try wake it manually first.