How to automatically enable custom modules upon theme activation?
As @4k4 mentioned there's ongoing development to Allow themes to declare dependencies on modules which hopefully lands in core with 8.6.0. Until then you are a little bit out of luck, except you find a place somewhere in your theme to trigger the following line of code:

\Drupal::service('module_installer')-&gt;install(['MYMODULE']);


Alternatively you could provide a second module which provides some button in the back-end which on-click triggers the above line PLUS the following two lines all at the same time.

\Drupal::service('theme_installer')-&gt;install(['MYTHEME']);
\Drupal::service('theme_handler')-&gt;setDefault('MYTHEME');




The background behind the issue mentioned above is that themes can't provide Drush 9 commands. As Drush 9 commands depend on certain services. But themes ain't allowed to provide these services. See the following issue: Allow themes to provide services.yml which was closed as won't fix.

The reason to close the service-issue (in a nutshell) is to keep things clean (from an OOP point of view) and don't let themes become other modules. Themes should provide templates, styles, scripts. Whereas modules should provide everything OOP-related, including services.

And as themes now (because of this decision) can't provide Drush commands anymore there must be away to allow them to rely on companion modules to provide useful commands/scripts and libraries for (sub-)theme development and maintenance. Which then will probably get activated automatically upon theme activation. So let's look forward and contribute to get this into core ASAP!