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' => [ 'render element' => 'form', 'template' => 'my-template-name', ], ]; } In the $form:
$form['#theme'] = 'mythemename'; And finally in the my-template-name.html.twig template:
<div class="someclass"> {{ form }} </div>