How can I exclude a particular category from my WordPress Page 1 and Page 2?

You’re nearly there, all that is left is to check on which page you currently are.

In the following code I’m first creating an array where the key corresponds to the page number and the value are the categories to exclude. This results in only one time writing $query->set(.... And to be really sure that a value exists for the key, I added isset().

<?php
function excludeCat($query) {
    $page = get_query_var('paged', 1);

    $exclude = [
        1 => '-3,-5,-23',
        2 => '...',
    ];

    if ($query->is_home && isset($exclude[$page])) {
         $query->set('cat', $exclude[$page]);
    }
    return $query;
}
add_filter('pre_get_posts', 'excludeCat');