Not every sort of earning is the same sort of earning. Suppose you buy a lottery ticket, picking five numbers. And suppose your numbers are chosen in the lottery, so that you win the million-dollar jackpot. Did you earn the money?
In one sense you did. There was a system (the lottery system) with rules; you followed the rules, and did the work that the system requires you to do to qualify for the money. So you earned it.
In another sense you did not. There was nothing about your particular action, considered in itself, that was worthy of a million dollars; all you did was pick five numbers and buy a ticket. Would that all our money came so easily. There is no proportion between service and return in winning the lottery. So you didn't earn it.
Consider another sort of case. Suppose you receive your million dollars because (God forbid) your brother dies, leaving it to you in his will on condition that you scatter his ashes on the open sea, which you do. Did you earn the money?
In a sense we would all allow that you did; your brother had it set in your will that you could receive a million dollars by following a procedure, and you followed that procedure. Your brother had the right to do what he did; and you did what you were supposed to do. So you earned it.
But, of course, in a very obvious sense you didn't earn it at all. There is no proportion between service and reward. So you didn't earn it.
In each of these cases we come up against a basic distinction about types of merit. There are two major types of merit, and each of them is very different.
Adequate merit, also called condign merit, is merit in the strictest sense of the term; it requires proportion between service and reward. It is the sense in which you can't earn windfalls like lotteries or inheritances or gifts, even if they come with requirements such that, if you fulfill them, you are rewarded. In cases of adequate merit, you receive your reward by strict commutative justice. For someone not to receive a reward they have merited condignly is a violation of personal justice -- the one who fails to reward them has wronged them, simply in virtue of the fact that they did what they did.
Nonadequate merit, more commonly called congruous merit, is merit in a weaker sense of the term; it merely requires that conditions be set up so that if you do a given thing you get a reward. You receive your reward not by commutative justice but by equity or by distributive justice, depending on the case. For someone not to receive a reward they have merited congruously is not a violation of personal justice; it is at most inappropriate or a violation of justice given the particular circumstances of the case.