EDIT: Actually you know what - there's no point fighting MS365. You'll save far more time if you just update the index in LibreOffice, Google Docs, or offline Word and then re-upload and check. It should also be noted that the Table of Contents will display differently when you view the doc online vs offline. So it could well be that you can ignore how the online version appears since that one will never reflect reality. Additionally, MS365 works better in Chrome/Edge than Firefox.
The following steps still don't work under certain conditions, but are a tantalising step closer as far as much simpler documents go. It's remarkable how easy it is to reproduce this bug though.
┬──┬╯︵ /(.□. \) (╯°□°)╯︵ ┻━┻