You are getting a wrong pagination because you’re modifying the query in the wrong place.
To modify the category/archive query you should do it using the ‘pre_get_posts’ action and setting the query args there.
in functions.php add:
function m_pre_get_posts( $query ) {
if (!is_admin() && !$query->is_main_query && is_category()) {
$query->set( 'posts_per_page', 2 );
} else {
return $query;
}
}
add_action( 'pre_get_posts', 'm_pre_get_posts' );
And in if the page is still redirecting to 404, you should check the default posts per page number set in the backend under Settings/Reading -> Blog pages show at most
By default it’s set to 10, and if you query posts with a number less than the default post per page number the page breaks and redirects to 404. Decrease the Blog pages show at most number and your page will work.