What does #optional mean for a "details" form element?
This is handled in the render element Details:

Details.php:

  public static function preRenderDetails($element) {
    ...
    // Do not render optional details elements if there are no children.
    if (isset($element['#parents'])) {
      $group = implode('][', $element['#parents']);
      if (!empty($element['#optional']) &amp;&amp; !Element::getVisibleChildren($element['#groups'][$group])) {
        $element['#printed'] = TRUE;
      }
    }
    return $element;
  }


If #optional is TRUE and there are no visible children, then the element is not rendered.