How to update global variables in plugin activation callback?

Thanks to @Tom J Nowell’s help, I fixed my code to persist the created page ID to Options:

function install_xxx() {    
    $post = array(
        'post_title'    => __( 'Thank You', 'xxx' ),
        'post_content'  => __( 'Lorem ipsum dolor.', 'xxx' ),
        'post_status'   => 'publish',
        'post_name'     => 'thank-you',
        'post_type'     => 'page'
    );

    $post_id = wp_insert_post( $post, true );
    add_option( 'xxx_thankyou_page_id', $post_id );
    error_log('Inserted page: ' . $post_id);
}

function uninstall_xxx() {
    $post_id = get_option( 'xxx_thankyou_page_id' );
    error_log('Removing page: ' . $post_id);
    if ( $page_id ) {
        $post = wp_delete_post( $post_id, true );
    }
}

register_activation_hook( __FILE__, 'install_xxx' );
register_deactivation_hook( __FILE__, 'uninstall_xxx' );