If you edit a discussion that was posted in a group or a space, it will remove itself from the group & space context and publish itself on the public forums.
As explained in the title.
If you create a discussion within a group or a space (closed group or open group, doesn't matter), it will be within that group, and will not be visible outside of the group on the main discussion's page's lists. That is all good.
However, after you edit an existing discussion that was posted in a group or a space, it will remove itself from the group & space context and publish itself on the public forums. There is no way to move it back to the group/space it belongs in.