Changes start from the bottom. Latest change is on top. Search and highlight all instances of id=

First I changed the heading a couple times. No duplicate IDs showed up. Then I created an anchor to an old heading. Then I changed the heading again.

A duplicate ID shows up only when I change back to an old heading. This is a rare event. Maybe Mediawiki could automatically remove that duplicate ID:
<span class="anchor" id="Current heading"></span> - in the wikitext.
<span class="anchor" id="Current_heading"></span> - in the page source.

Basic Format. Test 1 edit

Page source after 2nd heading change from "Basic Format" to "Basic Format. Test 1". Note the duplicate ID.

<h2><span class="mw-headline" id="Basic_Format._Test_1">Basic Format. Test 1 <span class="anchor" id="Basic_format._Test_1"></span></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=User:Timeshifter/Sandbox197&amp;veaction=edit&amp;section=1" class="mw-editsection-visualeditor" title="Edit section: Basic Format. Test 1">edit</a><span class="mw-editsection-divider"> | </span><a href="/w/index.php?title=User:Timeshifter/Sandbox197&amp;action=edit&amp;section=1" title="Edit section: Basic Format. Test 1">edit source</a><span class="mw-editsection-bracket">]</span></span></h2>

Page source when heading was "Basic Format". After adding anchor to previous name: {{subst:anchor|Basic format. Test 1}}

<h2><span class="mw-headline" id="Basic_Format">Basic Format <span class="anchor" id="Basic_format._Test_1"></span></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=User:Timeshifter/Sandbox197&amp;veaction=edit&amp;section=1" class="mw-editsection-visualeditor" title="Edit section: Basic Format">edit</a><span class="mw-editsection-divider"> | </span><a href="/w/index.php?title=User:Timeshifter/Sandbox197&amp;action=edit&amp;section=1" title="Edit section: Basic Format">edit source</a><span class="mw-editsection-bracket">]</span></span></h2>

Page source after changing back from "Basic Format. Test 1" to "Basic Format":

<h2><span class="mw-headline" id="Basic_Format">Basic Format</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=User:Timeshifter/Sandbox197&amp;veaction=edit&amp;section=1" class="mw-editsection-visualeditor" title="Edit section: Basic Format">edit</a><span class="mw-editsection-divider"> | </span><a href="/w/index.php?title=User:Timeshifter/Sandbox197&amp;action=edit&amp;section=1" title="Edit section: Basic Format">edit source</a><span class="mw-editsection-bracket">]</span></span></h2>

Page source after heading change from "Basic Format" to "Basic Format. Test 1":

<h2><span class="mw-headline" id="Basic_Format._Test_1">Basic Format. Test 1</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=User:Timeshifter/Sandbox197&amp;veaction=edit&amp;section=1" class="mw-editsection-visualeditor" title="Edit section: Basic Format. Test 1">edit</a><span class="mw-editsection-divider"> | </span><a href="/w/index.php?title=User:Timeshifter/Sandbox197&amp;action=edit&amp;section=1" title="Edit section: Basic Format. Test 1">edit source</a><span class="mw-editsection-bracket">]</span></span></h2>

Initial page source when heading was "Basic Format":

<h2><span class="mw-headline" id="Basic_Format">Basic Format</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=User:Timeshifter/Sandbox197&amp;veaction=edit&amp;section=1" class="mw-editsection-visualeditor" title="Edit section: Basic Format">edit</a><span class="mw-editsection-divider"> | </span><a href="/w/index.php?title=User:Timeshifter/Sandbox197&amp;action=edit&amp;section=1" title="Edit section: Basic Format">edit source</a><span class="mw-editsection-bracket">]</span></span></h2>