From what i understood:
The Hadith is:
Abu Hurayrah (radiallaahu 'anhu) reported that the Prophet (sallallaahu alaihi wasallam) said: "
Whenever Allah wills good for a person, He subjects him to adversity." [ Bukharee and others ]
'When you see anyone in a difficulty, understand that he is being punished for a sin'
That does not contradict the fact that Allaah tests those whom He loves. Since Allaah loves a person, He is punishing them in this life so that they will be free of sins in the Aakhirah and on the Day of Judgement. We know that for any suffering a Muslim goes through, some of his sins are expiated, and the reason he goes through the hardship in the first place is because of his sins. The following Ahadith explains it:
Anas (radiallaahu anhu) reported that the Prophet (sallallaahu alaihi wasallam) said: "When Allah wills good for a servant of His, He expedites his punishment in this life; and when He wills retribution for a servant of His, He holds his sins for Him to judge him by them on the Day of Resurrection."
[Tirmithee]
Abu Hurayrah (radiallaahu 'anhu) reported that the Prophet (sallallaahu 'alaihi wasallam) said: "Hardships continue to befall a believing man and woman's body, family, and property, until they meet Allah (swt) burdened with no sins." [ Tirmithee ]
Abu Sa'eed al-Khudree (radiallaahu anhu) reported that the Prophet (sallallaahu alaihi wasallam) said: "A muslim is not afflicted by hardship, sickness, sadness, worry, harm, or depression - even if pricked by a thorn, but Allah expiates his sins because of that. " [Bukharee and Muslim]
'Aishah (radiallaahu anhu) narrated that once some pain afflicted the Prophrt (sallallaahu alaihi wasallam) causing him to suffer and turn about in his bed. She said: "Had one of us done this, you would have blamed him." He (sallallaahu alaihi wasallam) replied: "An ailment is intensified for the righteous. whenever a believer is afflicted by a hardship, whether it is a thorn or more, a sin is taken off from him because of it, and he is elevated by one rank (in Jannah)." [ Ahmad ]
So because Allaah loves this person, He sends him trials and problems here, as a 'punishment' in this Life, so he won't be burdened with it on the Day of Qiyamah. If the person is patient for the sake of Allaah, then Insha'Allaah the above hadith apply to him.
"Indeed amazing are the affairs of a believer ! They are all for his benefit; If he is granted ease of living he is thankful; and this is best for him. And if he is afflicted with a hardship, he perseveres; and this is best or him." [ Muslim ]