I just tested this and it is working as expected, altering both sides.
I did not test this part
$custom_id = get_field($post_type_singular_slug . '_id', $post->ID);
if ($custom_id) {
$title = sanitize_text_field($custom_id) . ' ' . $title;
}
but I don’t see anything wrong with it provide the field you are trying get exists on the post.