Your question is unclear because it seems to assume that ihm is ambiguous as to case in the same way that euch is. But it isn't. Accusative and dative of er are still distinguishable in standard German: ihn vs. ihm. (In many dialects this is no longer the case.)
The case system very often provides redundant information. This is one reason why it's generally in a process of dissolution. (In a few dialects there are opposite tendencies.) It doesn't exist because it was ever needed. It exists because it evolved out of postpositions. Postpositions are like prepositions except they are placed after the noun they refer to. They must have been standard once in the evolution of Indo-European, but nowadays we have only a few. (E.g. in English: ago, aside, notwithstanding. In German: zufolge, halber.)
In the same way that the Indo-European case system with suffixes once evolved out of postpositions, English and French are probably in the process of developing case systems with prefixes right now, out of the prepositions to/à and of/de and possibly some others. In the case of French de, the process of merging with the following word has already started (d' before vowels).
Naming the case of a part of speech in a given sentence is not a natural task, so it's not something native speakers are particularly good at. This is why we need the trick described by Daniel B.
The distinction of ihn and ihm is occasionally relevant. E.g. consider the sentences "Gib den Ball dem Hund", which in context may be shortened to "Gib ihn ihm". Colloquially, someone might actually form the ellipsis "Gib ihn" or "Gib ihm", stressing either what is to be given or the recipient. (Note that for some reason nobody says "Gib ihm ihn", even though "Gib dem Hund den Ball" is actually more common. Just like "Give it him" is normal in English was still normal in Dickens's time and "Give him it" isn't. wasn't.)
It is much harder to come up with a parallel example involving the sequence of words euch [accusative] euch [dative], so in practice it really doesn't matter that accusative and dative are not distinguishable for the second person plural pronouns.