This edge case occurs when setting a new value for "player.opened" and the "on_gui_closed" event changes the players controller type.
I believe this is a bug because at no point is the value of "player.opened" set to the new value (not during close, during open or after).
I have found a work around for now which is to set "player.opened" to nil before setting your new value. (see ln70 in sample)
This work around suggests that the issue only exists when close and open are called during the same operation.
In the provided sample the case can be reproduced with the commands "/spectate" then "/display message":
Sample Code
The output (in chat) from this sample is shown below. The right hand image shows the output with the work around.
Sample Output