There is no feature directly comparable to the auto-generated Tables of Contents found on, for example, Wikipedia.
Here are some examples of ways in which folks work around this:
ToC in the question, links to separate questions works well for extremely broad topics that are best separated into distinct, specific questions.
ToC in the question, links to answers below works well for deceptively-broad topics that may have different answers depending on the context / specific needs of the asker.
No explicit ToC, just links to related topics where they're relevant works well for answers that are self-contained but touch on related topics that would require a full answer (or multiple answers) to explain in detail.
No explicit ToC, just reference sections by name where they're relevant works well for relatively short answers where background information is broken off to avoid distracting from the core answer.
All of these are quite rare; most answers - even long, detailed answers - do not need to break up the text in the same way that an encyclopedia article might, as they remain focused on solving a specific problem rather than attempting to exhaustively document a topic. Of the four, #3 is probably the most common, and isn't limited to referencing only Stack Overflow questions; lists of articles and documentation on external sites can be valuable additions to many answers where including such information inline would be a distraction.
Note also that many questions that would benefit from such techniques border on being "too broad" and would benefit from being broken up into smaller, more specific questions. Exceptions tend to be those "deceptively simple" questions that get asked a lot in various forms, where the value of having a comprehensive answer (or set of answer) trumps the cost of creating such comprehensive answers.