The option to Master a dragon unlocks when that dragon has reached level 60.
In order to Master a dragon, you will need fodder dragons of the same rarity and element, gold, and Books of Amorru. You can get Books of Amorru from the Ancient Ruins.
When you unlock the option to Master your dragon, you will be able to increase certain stats based on that dragon's role (e.g. Attack Type, Recovery Type, etc.). The amount also differs for different rarities of dragons. For example, Normal dragons can get up to 21% Evasion from Mastery, whilst Legendary dragons can get up to 30% Evasion.
Consider your dragon's role in your team, what stats are the most useful, and what stats are difficult to get from runes that requires it to be boosted by Mastery.
The cost of Mastery is a base price multiplied by the Mastery level. For example, Mastery level 1 for a Rare dragon is 200,000 gold, and Mastery level 2 is 2 (the Mastery level) x 200,000 (the base price), which is 400,000 gold. The Books cost is always the same. For Rare dragons, it is 10 Books of Amorru, and this is the same at Mastery level 1, 2, and so on.
The price of Mastery for Normal dragons is omitted, as it is unlikely you will need it. For reference, however, the base price of Mastery for Normal dragons is 50,000 gold and 1 Book of Amorru.
The costs of Mastering your Rare, Heroic, or Legendary dragon at each level are displayed below.