How do I theme a custom form?
I've just been encountering a similar problem. And solved it like following.

In my MYMODULE.module file:

function MYMODULE_theme($existing, $type, $theme, $path) {

  return [
    'mythemename' =&gt; [
      'render element' =&gt; 'form',
      'template' =&gt; 'my-template-name',
    ],
  ];
}


In the $form:

$form['#theme'] = 'mythemename';


And finally in the my-template-name.html.twig template:

&lt;div class="someclass"&gt;
  {{ form }}
&lt;/div&gt;