This is the basic thing explained in Bhagavadgita and our other books. In short, karma continues as long as our material conditioning lasts and sometimes it's not spend in one lifetime but over several lifetimes.
In cases of advanced devotees the 'bad thing' is actually Krsna's arrangement to make the devotee more surrendered to Him.