setErrorByName not working properly if field is in #details
Answer provided by Clive in comment is the correct one.

$form_state-&gt;setErrorByName('person2][lastname2', $this-&gt;t('This field is required.'));


Though if you just want to make the field required it would be better to do:

$form['person2']['lastname2'] = [
  '#type' =&gt; 'textfield',
  '#title' =&gt; $this-&gt;t('Last Name'),
  '#size' =&gt; 32,
  '#default_value' =&gt; $this-&gt;store-&gt;get('lastname2') ? $this-&gt;store-&gt;get('lastname2') : '',
  '#required' =&gt; true,
];