Add custom access check to user page
I ended up using hook_ENTITY_TYPE_access():
use \Drupal\Core\Entity\EntityInterface;
use \Drupal\Core\Session\AccountInterface;
use \Drupal\Core\Access\AccessResult;
use \Drupal\Core\Access\AccessResultInterface;
/**
 *
 * Implements hook_ENTITY_TYPE_access().
 */
function my_module_user_access(EntityInterface $entity, $operation, AccountInterface $account) {

  // Deny access to user profile for other members if the user hasn't accepted the terms
  if (!$entity-&gt;id() === $account-&gt;id() 
      || !$entity-&gt;hasField('field_profile_visibility')
      || $entity-&gt;get('field_profile_visibility')-&gt;value === NULL) {
    \Drupal::messenger()-&gt;addWarning(t('The profile is not visible because this user has not accepted the terms of this site yet.'));
    return AccessResult::forbidden();
  }
  return AccessResult::neutral();
}