Why does pressing the left command key sometimes trigger a window from Virtualbox I installed Ubuntu under virtualbox under OS X IN MacBook Pro. 

A while ago, I asked a question about how to switch between windows in the guest Ubuntu by keystrokes, and the reply at https://apple.stackexchange.com/a/241981/12994 suggested to press the left command key once before pressing alt-tab.

It sometimes works, but sometimes immediately following pressing the left command key, Virtualbox will pop up a window saying:


  You have clicked the mouse inside the Virtual Machine display or
  pressed the host key. This will cause the Virtual Machine to capture
  the host mouse pointer (only if the mouse pointer integration is not
  currently supported by the guest OS) and the keyboard, which will make
  them unavailable to other applications running on your host machine.
  You can press the host key at any time to uncapture the keyboard and
  mouse (if it is captured) and return them to normal operation. The
  currently assigned host key is shown on the status bar at the bottom
  of the Virtual Machine window, next to the ￼ icon. This icon, together
  with the mouse icon placed nearby, indicate the current keyboard and
  mouse capture state. The host key is currently defined as Left ⌘.


and asks me whether to choose cancel or capture.

Why does it sometimes work and sometimes brings out the interrupting Virtualbox window? How shall I switch between windows in the guest Ubuntu?

Thanks.
It's because your mouse and keyboard is captured by the VM instance.

When you mouse is captured in the VM window, pressing the Left ⌘ Cmd will bring up the window you described.  When it's not captured, it won't.

If you want to avoid this problem, instal the Guest Additions.