Seems to happen more frequently after I used Alt-Tab.
When the menu is detached in this way, it is still functional, as if it where running in another thread.
I seem to vaguely remember having a similar problem with my own custom popup ctrl and I couldn't find a way to get it to receive events to close itself when the parent loses focus because it gains focus when created, automatically causing the parent to lose focus; so you end up in this weird catch 22 situation where you want to close the popup when the parent window loses focus to something other than the popup window itself.
Then there's the issue of doing it reliably in a cross-platform way. It's probably going to take someone who knows the windowing system internals better than I do to fix it and I'd like to hear after they fix it how exactly they did it