Punishment might not be the right translation, though it is one of the meanings.
The Prophet salla Allahu alaihi wa sallam said: traveling is a piece of torment! The same word was used with the mentioned hadeeth; a man is tormented by the wailing of his family.
Scholars say, either this is for someone who instructed his family to wail after he dies or he knew that they will do that and didn’t instruct them not to.
Other scholars said that this is general and to all deceased and this is not a punishment but rather a feeling they get when they see the grief of their family.