For example, if you need to learn mass blessing, your hero needs to raise the life magic to level 3, and build 3 levels in the castle (if that magic is available there).
In general, you can gain magic in several places (not just in the castle), but you definitely need the corresponding secondary skill...