How do I set a validation error on a component inside a composite component?
The element name "sample_details][date_sampled]" specified in the first parameter of setByErrorName is not correct.

It should be 

// $key = your multi field array key eg 0,1,2,3 
$formState-&gt;setErrorByName('sample_details][items][' . $key . '][_item_][date_sampled', $this-&gt;t('must not have a sample date in the future.'));


You can find out the exact element name by two methods:


$formState-&gt;getUserInput() will give you the exact array pattern to use for setting error by name.
Inspect the element from the browser and use the value of name attribute.