You can't. TextEdit is just a simple text editor with Rich Text Format (RTF) and HTML capabilities which happens to be able to open Word documents too.
Word however uses (as you can clearly see) special code to create tables of content. This is required since a ToC is not just plain text, but actually intelligently references the headlines and their corresponding page. As mentioned here:
The only things that TextEdit doesn’t reliably interpret are special features like tables of contents or footnotes — those will often show up bizarrely.
Now, you can create references in RTF, but this actually requires you to write RTF code. This is nothing TextEdit can do for you automatically. You could also write HTML code yourself, using named anchors, but that only produces HTML, not Word files.
If you're looking for something less buggy than Word for Mac, consider trying Apple's own Pages, which handles Word document formats and provides a more nicely integrated user interface. It's also very stable.