Disconnecting & Connecting macbook pro to Apple display My mac behaves weirdly while connecting and disconnecting to Apple 27" display. 

Disconnecting: 
At the end of the day when i'm taking my mac &amp; disconnecting it for my desk display I just disconnecting all the cables thunderbolt usb and power, then when I'm opening my mac in the train , it's stuck and laggy the dock is disappearing, only hard shut down helps. 

Connecting: 
Nearly same thing here , when i'm connecting the mac starting a new day, 
Again the mac is laggy and the dock is hovering somewhere in the middle of the screen, but here I can leave the mac for 10 min and it goes back to itself... everything in place and no more lags. 

-Tried to disconnect it in sleep mode , doesn't help. 
-While i'm working with the display the mac cover is closed. 

someone here familiar with it ? any help will be appreciated 

Thanks,
To be honest, I've found for many users it's best to just shutdown their MacBook prior to disconnecting it from a display (especially if it's also drawing its power from the display). 

However, you should also be able to just put your Mac to sleep prior to unplugging the display and Apple actually recommends at least doing so:


  It's best to put your Mac to sleep by choosing Apple menu > Sleep before disconnecting your display.


Source: Apple

Also, only some DVI and Mini DisplayPort displays can be unplugged without putting the computer to sleep, but since you're using an Apple 27" display (which should be fine), you can try resetting the NVRAM to see if this addresses your issue.

Resetting the NVRAM on your model MacBook Pro

Older Macs had what's called Parameter RAM (PRAM), newer Macs use Non-Volatile Random-Access Memory (NVRAM). In your case here’s how to reset it (I recommend doing this using the built-in keyboard and while your MBP is not connected to the display):


Shut down your machine. Yes, a full shut down, not just logging out.
Press the power button and then press the commandoptionPR keys. You have to make sure you press these keys before the gray screen appears or it won’t work.
Hold those keys down until your Mac reboots again and you here the startup chime.
Let go of the keys and let your Mac reboot normally.


Note: When you log back in you may need to readjust some of your system preferences (e.g. speaker volume, screen resolution, startup disk selection, time zone information, etc).

Resetting the SMC on your model MacBook Pro

If, after resetting the NVRAM, you notice no difference, you can also reset the SMC.

Follow these instructions to reset the SMC on your model MacBook Pro (once again, I recommend doing this using the built-in keyboard and while your MBP is not connected to the display):


Shut down your computer
Keep the MagSafe adapter (power cable) plugged in.
Press at the same time shiftoptioncontrol (on the left side of the keyboard) and the power button
Let go
Turn your computer back on with the power button.


Further reading:


Use your Mac notebook computer in closed-display mode with an external display