filter the title changed also the page titles

When you’re using get_post_meta() and the post meta doesn’t exist for that post (or page or custom post type), then the function returns either an empty array or empty string depending on if the third parameter is false (default) or true. Since you’re passing true as that parameter, you can check if either the first name or last name is equal to an empty string. If so, then you can return the $title unaltered.

You can also add a check using is_singular() if you only want the filter applied on certain post types.

add_filter( 'the_title', function( $title, $id ) { 
    //* Only use this filter on `your-custom-slut` post types
    if( ! is_singular( 'your-custom-slug' ) ) {
      return $title;
    }
    $fn = esc_html( get_post_meta( $id, 'first_name', true ) ); 
    $ln = esc_html( get_post_meta( $id, 'last_name', true ) );
    //* Use default if either the `first_name` or `last_name` isn't defined
    return ( '' === $fn || '' === $ln ) ? $title : $fn . ' ' . $ln;
}, 10, 2 );