This is the bug that sort-lines since Emacs 25 has not handled collapsed (invisible) lines properly (keeping them with their parents) when sorting. Prior to Emacs 25, sort-lines handled outline sorting properly.
It should be a fairly straightforward thing (relative to the complexity of other Emacs issues) since it is well understood and a potential patch has been offered. Eli suggested that any change be limited to outlining modes to limit its effects.
I cannot work on it myself right now and that is why I am asking someone else to pick it up.
I think this is a bug that should be eliminated before Emacs 26 goes live so it does not impact people with large outlines who might sort them and get the wrong results but not notice until their data has been corrupted for a while and they can't get back to the original proper hierarchical associations.
At the very least the present behavior makes no sense for outline modes that use invisibility for collapsing.