Merit is a word about earning, and its relatives prove the point. It comes from Latin meritum, the neuter past participle of merēre — 'to earn, to deserve'. In Roman usage, meritum was neutral: you merited reward for good deeds and punishment for bad ones.
The Proto-Indo-European root *mer- meant 'to receive one's share', and it generated a word family centred on exchange and earning. Merchant comes from Latin mercāns — one who earns by trading. Market comes from mercātus — a place of trade. Commerce combines com- ('together') with merx ('goods') — trading together.
The most surprising member of the family is mercy. Latin mercēs meant 'wages, fee, reward' — the price for something. In early Christian Latin, the word shifted: mercy became the price that God chose not to exact. Where merit is what you deserve, mercy is what you are spared from deserving. The two words, from the same root, became moral opposites.
Meritocracy — government by merit — was coined in 1958 by Michael Young, and he meant it as a warning, not a compliment. His book predicted that a society selecting purely on merit would become as rigid and unjust as an aristocracy.
The legal phrase 'on its merits' preserves the oldest sense: judging a case by what it actually deserves, stripped of procedure and precedent.