WordPress actually provides a few different ways you can modify the sitemap.
The first is using the wp_sitemaps_posts_query_args filter which allows you to modify the query WordPress uses to get posts for the sitemap.
If you know the IDs of the posts/pages, you can modify the query like Brett mentioned in another comment:
add_filter('wp_sitemaps_posts_query_args', function($args, $post_type) {
// set the page IDs to exclude
$args['post__not_in'] = array(111, 222, 333);
return $args;
}, 10, 2);
If you don't know the IDs of the posts/pages, but you know the permalinks, there is another way you can modify the sitemap: the wp_sitemaps_posts_entry filter. This filter allows you to modify the sitemap entry for an individual post. See: https://github.com/WordPress/wordpress-develop/blob/6.8.2/src/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php#L164-L164
WordPress passes the entry through a filter like so:
$sitemap_entry = apply_filters( 'wp_sitemaps_posts_entry', $sitemap_entry, $post, $post_type );
Where $sitemap_entry is an array of all the fields that make up the entry for the sitemap. If you know the url of the post/page you'd like to exclude you can filter it like so:
add_filter('wp_sitemaps_posts_entry', function($sitemap_entry, $post, $post_type) {
// if it's a page post type
if( 'page' === $post_type) {
if ( isset( $sitemap_entry['loc'] ) && $sitemap_entry['loc'] === "https://yourdomain.com/the-url-of-the-page-you-want-to-exlude" ) {
$sitemap_entry = [];
}
}
return $sitemap_entry;
}, 10, 2);
By the setting the entry to an empty array ([]) WordPress won't include it in the sitemap.
References