Capabilities can be assigned to roles in a context. CONTEXT_COURSE is not a context, it is a context level for all course contexts, so you cannot assign a capbility like that.
It would help if you explain exactly what end result you want, rather than how you are trying to achieve it, but the way moodle handles default capabilities is by setting archetypes in the capability definition. Roles that use that archetype will automatically have the capability set. See the Roles documentation here: https://docs.moodle.org/dev/Roles#Programming_Interface