How to detect when a user changes their name?

The hook you’re looking for is insert_user_meta.

add_filter( 'insert_user_meta', function( $meta, $user, $update ) {
  if( true !== $update ) return $meta;
  $old_meta = get_user_meta( $user->ID );
  if( $old_meta[ 'first_name' ] !== $meta[ 'first_name' ] ) {
    //* Do something
  }
  return $meta;
}, 10, 3 );

error code: 523