We have the same "problem" in the 10 commandments as recorded on Ex 20:
4 You shall not make for yourself an idol in the form of anything in the heavens above, on the earth below, or in the waters beneath.
5 You shall not bow down to them or worship them; for I, the LORD your God, am a jealous God, visiting the iniquity of the fathers on
their children to the third and fourth generations of those who hate
Me, 6 but showing loving devotion to a thousand generations of
those who love Me and keep My commandments.
Possibly the best way to explain the distinction here (which is two-fold) is to examine the story of David following the rape of Bathsheba and the murder of Uriah. Note the record in 2 Sam 12:
7 Then Nathan said to David, “You are that man! ... 9 Why then have you despised the command of the LORD by doing evil in His sight?
You put Uriah the Hittite to the sword and took his wife as your own,
for you have slain him with the sword of the Ammonites. 10 Now,
therefore, the sword will never depart from your house, because you
have despised Me and have taken the wife of Uriah the Hittite to be
your own.’
11 This is what the LORD says: ‘I will raise up adversity against you from your own house. Before your very eyes I will take your wives
and give them to another, and he will lie with them in broad daylight.
12 You have acted in secret, but I will do this thing in broad daylight before all Israel.’ ”
13Then David said to Nathan, “I have sinned against the LORD.”
“The LORD has taken away your sin,” Nathan replied. “You will not die.
14 Nevertheless, because by this deed you have shown utter contempt for the word of the LORD, the son born to you will surely
die.”
Note that the moment David recognized his sin and confessed (V13) Nathan immediately proclaimed him forgiven.
However (and this is the crux of the matter) David still had to endure the earthly consequences of his heinous sins which would be:
- Four of sons would die (V6) which were - the son born to Bathsheba (V18), Amnon (2 Sam 13), Absalom (2 Sam 15-18), Adonijah (1 Kings 2:25)
- Davids 10 concubines were raped by his own son (2 Sam 16:21, 22)
- David's own son mounted an almost-successful rebellion (2 Sam 15-18)
Thus, while David was forgiven, his family and all Israel felt the consequences of his great sin. David might have prevented some of this if he were not so morally wounded himself. That is, some of the consequences of David's sin corrupted him so that his judgement was not as astute as it might have been.
Lastly, not that while four of David's sons died, Amnon, Absalom and Adonijah all died for their own sins, not David. That is, while they died for their own sins, it was David who's evil deeds set in train a series of events that had catastrophic consequences for himself and those around him.
Another way to explain the difference between Deut 24:16 and Num 14:18 is to say that Deut 24:16 is speaking about the punishment for sin, while Ex 20:5 and Num 14:18 is speaking about the natural consequences of evil. God forgives but only rarely removes the consequences of a persons sinfulness.