You are running into this:
https://github.com/gohugoio/hugo/issues/4507
This is a detailed description of the situation:
https://discourse.gohugo.io/t/determine-if-current-page-is-result-of-pagination/37494/4
The trick is to paginate before trying to access the pager number.
https://discourse.gohugo.io/t/control-pagination-and-page-collections-from-baseof-html/37643/8
The second topic includes a detailed example that you can clone and test.