Praise be to Allaah.
He should look at this forbidden thing and if the transaction was with a Muslim, then it is not permissible for him to pay the debt, because when Allaah forbids a thing He also forbids its price, and because whatever it is forbidden to sell in Islam has no price. The Prophet (peace and blessings of Allaah be upon him) forbade the price of a dog and said: “If he comes asking for its price, then fill his palm with dust.” This is reported in Al-Saheeh from the hadeeth of Ibn Abbaas.
It was reported from Abu Mas’ood al-Ansaari (may Allaah be pleased with him) that the Messenger of Allaah (peace and blessings of Allaah be upon him) forbade the price of a dog, the earnings of a prostitute and the fee (hulwaan) of a fortune-teller (narrated by al-Bukhaari, 2083). The word hulwaan comes from the phrase “halawtuhu hulwaanan”, meaning “I gave it to him”; the root of this word is al-halaawah (meaning “sweet”) and it is likened to something sweet because he takes the money so easily, without having to work hard or make any effort… Hulwaan also means “bribe.”
But if a person is forced to repay the debt, then in this case he should pay it whilst seeking the forgiveness of Allaah and repenting to Him for buying haraam things, whether from a Muslim or anyone else.
If the transaction was with a non-Muslim in whose religion the thing he sold is not viewed as forbidden, then the debt has to be paid whilst also repenting. The Muslim has to avoid dealing in things that Allaah has forbidden.
Sheikh Muhammed Salih Al-Munajjid