It’s a common enough word that few people stop to think how odd comeuppance really is. Why should it mean the punishment or fate that someone deserves, a just retribution or just deserts?
The Oxford English Dictionary directs enquirers about its origin to sense 74 of the verb come, implying that it derives from come up. That’s reasonable, since the most common early written form in the US — where the word seems to have been invented around the middle of the nineteenth century — was come-up-ance, which we may guess is the situation or consequence of having come up.
The OED and some other dictionaries suggest it refers to coming up before a judge or court for judgement. That’s supported by the earliest evidence for the related expression come-uppings, known in American English from rather later:
I was led away, and I got my come-uppings, or the other fellow’s come-uppings, for I wa’n’t to blame any, and I always said so, and I guess the judge would say so too, if it were to do over again.
The Minister’s Charge, by William Dean Howells, 1886.
Curiously, come-upping is recorded in Cornish dialect in 1880 in the sense of a flogging. It’s possible that it’s a quite separate form, which was taken to the US by migrants and became associated with come-up-ance.