I'm tempted to apply the following patch, as this problem falls under
the category of "inserting in an invisible region". I don't think it
breaks any non-interactive call of org-insert-heading, but this needs
further checking.
Also, note that the problem occurs only when there is no blank line
between the :END: and the following headline, so maybe the real fix
has to be within org-insert-heading...
diff --git a/lisp/org.el b/lisp/org.el
index 8c55bd4..4d16682 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7495,6 +7495,7 @@ and create a new headline with the text in the current line after point
When INVISIBLE-OK is set, stop at invisible headlines when going back.
This is important for non-interactive uses of the command."
(interactive "P")
+ (org-check-before-invisible-edit 'insert)
(cond
((or (= (buffer-size) 0)
(and (not (save-excursion
--
Bastien