Building a table of contents for a webpage helps with SEO/SEM, and helps the author think about contents of the document.
Most use H1 to H6 heading tags to build the table of contents.
In WordPress, use either the built-in Gutenberg Table of Contents block, or add a plugin.