Replace post title based on conditions

You can use the_title filter to modify the post_title prior to printing on the screen.

add_filter("the_title", function($title, $id)){
  $user = wp_get_current_user();
  if((!is_user_logged_in() || in_array("pending", $user->roles)) && "post" === get_post_type($id)){
    $title = "Custom title";
  }
  return $title;
}, 10, 2);

source: https://developer.wordpress.org/reference/hooks/the_title/