Pagination not working past page 3 on archive page of category

I had a similar issue and maybe this is also helpful when pagination is only working sometimes: e.g. /page/1/ and /page/2/ are working and /page/3/ not. Result: Error 404. Problem is: default value (12 items each page) for posts_per_page (WordPress Settings/Reading) is loaded always from database before the template is loaded. So $args=[‘posts_per_page’ => 1] in custom_post WP_Query($args) has effect on pagination and number of loaded elements but not on paged rewrite Rule!
Proposed solution is to add pre_get_posts() to function.php and separate by custom post_type. Example:

//Add to functions.php because it have to be loaded before template loading
function hwl_home_pagesize( $query ) {
    if ( get_post_type() == "your_custom_post_type" )
        $query->query_vars['posts_per_page'] = 2; //same as in WP_Query arg or add to WP_Query arg get_option('posts_per_page')
}
add_action('pre_get_posts', 'hwl_home_pagesize', 1);

see also: https://core.trac.wordpress.org/ticket/22299 (From my point of view, it is still an architecture issue, no matter what was already said 9years ago.)