As David said in the comments, you need several runs of LaTeX to solve problems like this. Actually LaTeX checks such discrepancies, and if the position of page references changes, it suggests you to rerun itself. Generally you need to rerun LaTeX until the logs no longer contain the phrase "Rerun LaTeX to get the references right".
The problem of page shifting due to TOC have been present in manual typesetting for a long time. Besides the iterative approach (note the page shifts, correct table of contents until no more changes) there are other approaches:
In Russian typographic tradition the table of contents is typeset in the end, rather than in the beginning, so no page shifting occurs.
In many books front matter pages and main matter pages are numbered separately, usually front matter in Roman and main matter in Arabic. Then adding pages to front matter does not shift main matter. You can achieve this effect using the commands \pagenumbering{roman}
(or Roman
for uppercase numerals) and \pagenumbering{arabic}
; note that \pagenumbering
resets the page numbers.
These approaches may decrease the number of LaTeX runs necessary to typset the text.