Word 365 / Word Online -- Insert Table of Contents disabled, how to insert a TOC?
Word online does not have the full feature set of Word for desktop.
Microsoft Word Online lets you make basic edits and formatting changes to your document in a web browser.
Some things can only be done in Word for desktop. For an overview of the differences between desktop and online, see
https://support.office.com/en-us/article/differences-between-using-a-document-in-the-browser-and-in-word-3e863ce3-e82c-4211-8f97-5b33c36c55f8#__toc309629521
If you want to insert a TOC, you have to do that in Word for desktop.
Don't shoot the messenger.
It does seem like this is such a basic and common feature that it woudl be included in Word Online, but as others have stated it isn't for some reason.
However, they do make it rather easy to open in Word for desktop (assuming you have it installed). Simply click the Open in Word link to the right of the main menu bar.
You don't have to even close the tab. When you click the link a pop-up will appear letting you know it is being opened on your desktop and you can resume editing when you're finished. Add the table of contents in Word on your desktop, save it and close the desktop app. Then click the link on Word Online to resume editing and your newly added table of contents is available in Word Online.