I have inserted a table contents into my manuscript using the Edit > Copy Special > Copy Documents as TOC feature. When I compile, the <$p> tags in this TOC don’t work. However, I am using those same tags in the header and footer, and those work as expected and insert the page number.
The page numbers are undefined until the document is actually assembled. So it’s up to the PDF rendering engine or Word (depending on format) to figure out what they should be.
If compiling to Word (DOCX format), then it’s as @AntoniDol indicated, Print Preview in Word. You’ll see the page numbers in the preview and cancelling the preview your TOC will be updated with the same numbers in Word.
Each time you compile, you must follow the same course of action for Word to update the placeholders.
If you save and close the Word document and open it again, you must go through the same process, as Word doesn’t save the actual page numbers, only the placeholders.
Compiling to PDF, however, produces a numbered TOC.
I use Office 365 - whatever this week’s latest version is and Scrivener 3.1.5.1.
In Word they are called “fields”. Fields are a core feature of Word and has been for decades. Fields need to be “updated” when they are new or out of date. Word provides a number of ways to “update fields” automatically or manually.