the application.config.php is one of the first elements loaded by the zf2 bootstrapping and are passed to the ServiceManager wich loop all Modules (and load) listed in the application.config.php. At this point doctrine is not loaded (so you can't check if a module is "actived" in you'r database ) with a script running with zend framework.
when you check the public/index.php you are able to see the line where the bootstrapping begin
// Run the application!
Zend\Mvc\Application::init(require 'config/application.config.php')->run();
this is your point where you logic should be implement (establish a database connection, create a application config) and pass it to the init() method.
but this is not a good idea, because you need to specify a db connection, set db passwords etc. and "go your own way without zf2".
when you disable modules dynamicly i think you make something "wrong", because either you need a module or you don't - either a module is enabled in development environment and disabled in your live environment. simple as it