WordPress 404 pagination (/page/2) error?

Pagination cannot be reliably implemented in template. It is resolved during load way before template it ever reached.

Unless you implement it from scratch (complete with rewrite) you need to be using pre_get_posts or other related hook to modify main query. Look around the site, there are plenty answer on topic of here.

tech