If you have duplicate sub headings the link generated for them in the table of contents will just lead to the first match it finds. For instance, if you had:
# A Heading !heading
## A Subheading !heading
# Another Heading !heading
## A Subheading !heading
The table of contents generates the link based on the heading text. So both links for A Subheading would be the first subheading content.