Custom Post-Rename Function Does Not Function in WordPress 6.x

The call to get_the_ID() possibly worked by happy coincidence of there being an available post object to pull the ID from. However, realistically you should have been looking at data available to the filter for this ID instead, here’s how.

First update you add_filter declaration to bring in the second variable from wp_insert_post_data.

add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 2 );

Then update your callback(function) to receive that additional data.

function modify_post_title( $data, $postarr ){

And update your ID variable with the value from $postarr.

$id = $postarr['ID'];

Hope that helps.