If you do not want certain section headings to be included in the table of contents, you can add two classes to the heading: unlisted and unnumbered. For example:
# Section heading {.unlisted .unnumbered}
Note that this feature requires at least Pandoc 2.8. You may check your Pandoc version via rmarkdown::pandoc_version(). If the version is lower than 2.8, you may install a newer version by following the instructions at https://pandoc.org/installing.html.