All perfect praise be to Allah, the Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad is His slave and Messenger.
Your question is somewhat ambiguous and confusing. In any case, the Sunnah clarified that the non-Muslim is not rewarded for his good deeds in the Hereafter. Rather, he is only rewarded for this in this worldly life. Anas ibn Maalik, may Allah be pleased with him, narrated that the Prophet said, “Allah does not wrong a believer regarding any good deed; he is given blessings for it in this worldly life and he will be rewarded for it in the Hereafter. However, the non-Muslim is given provision in this worldly life as a reward for his good deeds which he performed, not for the sake of Allah, and when he comes to the Hereafter, there is no good deed for him for which he can be rewarded.”
As for what you mentioned about a person who is indebted with good deeds for another person, then we do not know any basis for this, unless you mean the hadeeth by Abu Hurayrah, may Allah be pleased with him, who narrated that the Prophet said, “Do you know who the bankrupt is?” They (the Companions) said, “The bankrupt amongst us is the one who neither has dinars nor dirhams (i.e. no money).” He said, “The truly bankrupt of my followers is the one who comes on the Day of Resurrection with prayers and fasts and zakah, but (he finds himself bankrupt on that day as he exhausted his funds of virtues) since he hurled abuses against some people, slandered some, unlawfully consumed the wealth of some, shed the blood of some, and beat some; and his virtues are then credited to their account (those who suffered at his hand). And if his good deeds fall short to clear the account, then some of their sins are entered in (his account) and he is thrown in the Hellfire.” [Muslim]
The retribution for a non-Muslim who is oppressed by an unjust Muslim in the Hereafter is absolutely confirmed. At-Tabari said about the interpretation of the verse: {Then indeed you, on the Day of Resurrection, before your Lord, will dispute.} [Quran 39:31] Allah says that, indeed, all of you, believers and disbelievers, on the Day of Resurrection, before your Lord, will dispute; Allah will take the right of the oppressed from the oppressor and will judge between all of you with the Truth.”
However, we do not know the details of that retribution.
Dr. Saalih Al-Fawzaan was asked, The non-Muslim will get legal retribution from the Muslim; how can this be? Will his punishment be reduced? He said, “Allah knows best. What is important is that retribution on the Day of Resurrection will take place between the people as a way of establishing justice, but how will the non-Muslim take retribution (from the Muslim), then Allah knows best.”
As regards a person who died while being indebted to people, then if he were able to repay his debt but failed to do so until he died, he will be asked for it in the Hereafter. However, if the debt was taken for a non-forbidden reason and he was unable to repay it until he died, then he will not be asked for it and he will not be held accountable for it in the Hereafter according to some scholars.
Al-Aadaab Ash-Shar’iyah reads:
“Whoever takes a loan for a permissible reason and he intends to repay it but was unable to do so until he died, then according to Imaam Ahmad, he will be held accountable for it in the Hereafter. It is not certain (it should be looked at) whether this is an explicit statement of Imaam Ahmad or if it is only something understood from his statements. I have not come across such a statement from the scholars of the Hanbali School, but the statement of Al-Qaadhi, Al-Aajurri, Ibn ‘Aqeel, Abu Ya'la As-Sagheer (son of Al-Qaadhi Abu Ya'la), and the author of Al-Muharrar [who was the grandfather of Ibn Taymiyyah] is that he is not held accountable for it. His spending of the money extravagantly and thriftily is not a reason to ask him for it – contrary to the view of Al-Aajurri – even though he is required to spend it in what is not forbidden.”
As for how to get legal retribution from the debtor in the Hereafter, we do not have more details about it than the hadeeth of Abu Hurayrah which was mentioned above.
You should know that the details of the accountability issues and other similar conditions of the Hereafter are matters of the Unseen, which can only be determined by text (revelation) or quotes from scholars, and there is no room for Ijtihaad (independent reasoning) in this. Moreover, investigating this matter does not lead to any action (doing good deeds), and it is no more than dispraised Takalluf (excessive and burdensome asking of questions without necessity).
Allah knows best.