Two things to be considered:
\afterpage command expands its contents in a group, so changes are reverted unless they are
\global. The effect of
\newgeometry is local, so nothing happens when you execute it inside
\afterpage command inserts its argument after the current page has ended, so if you do
<something> will be inserted in the page that follows the end of the first
\lipsum (which is, in this case, past the middle of the document).
To work around these issues I used
\restoregeometry instead, which is only one token, so it can be easily inserted
\aftergroup, and I moved the call to
\afterpage right at the beginning of the document, so it will take effect once the first page ends.