If a module, theme or profile provides configuration that has additional dependencies that might not be met during its installation then this configuration should be stored in config/optional. For example, the Node module provides the frontpage view. The Node module does not depend on Views. Therefore, views.view.frontpage.yml must be stored in Node's config/optional directory.
When an extension is installed its config/optional directory is searched for any configuration which can be installed. Any configuration whose dependencies cannot be met is ignored. When a module is installed that provides a configuration entity type, for example Views, all installed modules' config/optional directories are searched for any configuration entities of the new type. If any configuration entities are found and their other dependencies can be met, the configuration entities are created. Given the original example of Views and Node, this means it does not matter which way around Views and Node are installed. If Node is installed first, the frontpage view is created when Views is installed. If Views is installed first, the frontpage view is created when Node is installed.
All configuration contained within a module's, theme's or profile's config/install must be created during an install. If any configuration cannot be created because of missing dependencies then a Drupal\Core\Config\UnmetDependenciesException exception is thrown. At this point the module or profile author can either, add the missing dependency to the list of dependencies in the extension's .info.yml file, or, move the configuration to config/optional. Themes can not directly depend on modules so all configuration entities created by themes should go in config/optional.