How can I prevent "Log in to post comments" from displaying for anonymous users?
You can do it using hook_preprocess_HOOK
The following hooks should be placed in YOURTHEME.theme file:


Remove comment links from node for Anonymous user:




    /**
     * Implements hook_preprocess_HOOK().
     */
    function YOURTHEME_preprocess_links__node(&$variables) {
      if (\Drupal::currentUser()->isAnonymous()) {
        unset($variables['links']['comment-forbidden']);
      }
    }




Remove links from the comments for Anonymous user:




/**
 * Implements hook_preprocess_HOOK().
 */
function YOURTHEME_preprocess_links__comment(&$variables) {
  if (\Drupal::currentUser()->isAnonymous()) {
    unset($variables['links']['comment-forbidden']);
  }
}