How can I make PHPStorm to auto-detect its dedicated variables?
You cannot.
${NAMESPACE}
is pre-defined/pre-filled only in bundled templates where PHP plugin provides special support for it. In all other cases it is treated as ordinary variable.
http://youtrack.jetbrains.com/issue/WI-21711
UPDATE: 2020-01-28
The aforementioned ticket is now resolved.
You can now select custom template when using "New PHP Class/Trait/Interface" dialog. ${NAMESPACE}
variable now gets taken from that dialog field (where it auto-detected based on your Source Roots settings and you can edit it manually if needed) and passed into the actual template.