I found the answer:
Implementing the hook_form_FORM_ID_alter()
hook you can use the comment form id (comment_comment_form
) to alter the form.
The problem was that the field name is inside the author, so you need to use $form['author']['name']['#required'] = TRUE;
/**
* Implements hook_form_FORM_ID_alter().
*/
function MODULE_form_comment_comment_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
$form['author']['name']['#required'] = TRUE;
}