Al-Tirmidhi (1456), Abu Dawood (4462) and Ibn Maajah (2561) narrated that Ibn ‘Abbaas (may Allaah be pleased with him) said: The Messenger of Allaah (peace and blessings of Allaah be upon him) said: “Whoever you find doing the action of the people of Loot, execute the one who does it and the one to whom it is done.” Classed as saheeh by al-Albaani in Saheeh al-Tirmidhi.
The Sahaabah were unanimously agreed on the executing of homosexuals, but they differed as to how they were to be executed.
Some of them, such as Abu Bakr al-Siddeeq and ‘Ali ibn Abi Taalib (may Allaah be pleased with them) thought that they should be burned to death. Some of them, such as Ibn ‘Abbaas (may Allaah be pleased with him) thought that they should be thrown from a tall building followed by stoning. Some of them thought that they should be stoned to death, which was narrated from both ‘Ali and Ibn ‘Abbaas (may Allaah be pleased with them).
See: al-Mughni (9/58).
The reason why the one to whom such an act is done should also be executed is because he is a partner in the sin, because this sin can only be committed if both parties take part, so it is only just to carry out the punishment on both of them. Similarly in the case of zina (adultery), the punishment is carried out on both the man and the woman. Moreover there is nothing good to be gained from letting the one to whom it has been done remain alive, because of the great evil that has befallen him and because of the great evil that may result from his presence.
It says in Mataalib Ooli al-Nuha (6/174): Even though adultery and homosexuality are both immoral deeds and are both evils that go against the wisdom of Allaah in His creation and His command, in homosexuality there are innumerable evils and it is better for the one to whom it was done to be executed than to let him repeat that evil action, because he has been corrupted in such a way that there is no hope of reform for him, and there is no goodness left in him, and after that he will not feel shy before Allaah or before His creation. The sperm of the one who did that will affect his heart and soul as poison affects the body, and he does not deserve to be guided to anything good, and every time he tries to do something good, something will happen to spoil his good deed, as a punishment to him. Hardly ever do you see one who was like that in his youth but he is the worst he can be when he grows old. He does not gain any beneficial knowledge or do any righteous deeds, or repent sincerely, in most cases. Once this is established, the evil consequences of homosexuality are among the worst of evil consequences, so its punishment is one of the most severe of punishments in this world and in the Hereafter.
The companions of the Messenger of Allaah (peace and blessings of Allaah be upon him) agreed unanimously that the homosexual is to be executed, and none of them differed concerning that. Rather they differed as to the method of execution. Some people thought that this difference means that they disagreed about executing him, so they narrated it as a matter concerning which the Sahaabah differed, but it is a matter concerning which there was consensus among them, not a matter of difference. End quote.
The source for this was Ibn al-Qayyim (may Allaah have mercy on him), who mentioned it in al-Jawaab al-Kaafi li man sa’ala ‘an al-Dawa’ al-Shaafi.
But if the one to whom it was done was forced, then he is not to be punished, because the Prophet (peace and blessings of Allaah be upon him) said: “Allaah has forgiven my ummah for mistakes and forgetfulness, and what they are forced to do.” Narrated by Ibn Maajah (2045); classed as saheeh by al-Albaani in Saheeh Ibn Maajah.
See also the answer to question no. 38622 for more information.
And Allaah knows best.