A table of contents and an index are both usually found at the beginning or end of a book, but they serve very different purposes.
The table of contents presents the structure of the book. It follows the order of chapters, sections or subjects, helping readers understand the arrangement and locate a particular unit by its place in the book.
An index presents the content by subject. It helps readers find a concept, question, ruling or discussion even when they do not know which chapter contains it, and when the same subject appears in several places.
A topic might be the main focus of one chapter, part of a wider discussion in another, and mentioned incidentally in a third. The table of contents will not necessarily reveal all these places because it reflects the chapter structure. A professional index gathers the relevant references under an appropriate entry, giving readers one starting point for finding them all.
The essential difference is this: a table of contents answers, What is in the book, and in what order? An index answers, Where does the book discuss the subject I am looking for?
That is why indexing involves more than collecting words from the text. A good index brings equivalent terms together, establishes a hierarchy, distinguishes between closely related topics and points to the precise passages where a subject is discussed.
The table of contents is a map of the structure of the book. The index is a map of access to the knowledge within it. Both matter, but each supports a different way of using the book.