See this example test blog: /members-area/b/blog/posts/test-of-table-of-contents-problem---spurious-entries-created
I think it happens when there is a "missing" heading level between one level and another, e.g. when going from text under a Heading 3 to a Heading 1 without an intervening block of text at Heading 2 level.