Imaam Abu Muhammad Al-Hasan b. `Alee b. Khalaf al-Barbahaaree (died 329H, rahimahullaah) stated in his Sharhus-Sunnah (point 40):
والصلاة على من مات من أهل القبلة سنة والمرجوم والزاني والزانية والذي يقتل نفسه وغيره من أهل القبلة والسكران وغيرهم الصلاة عليهم سنة
And the Funeral Prayer over the deceased Muslims (Ahlul-Qiblah) is a Sunnah: This includes the one who is stoned to death for adultery, the fornicating man and woman, the one who kills himself, and other than them from the People of Qiblah such as the drunkard and so on – praying the Funeral Prayer over them is a Sunnah.
Explanation of Shaikh al-Fawzaan:
It-haaf al-Qaaree of Shaikh al-Fawzaan vol. 1, p. 271 onwards):
This is as has already preceded [in point 39]: that the one who manifests Imaan and Islaam, then we pray the Funeral Prayer (Janaazah) over him – and he is considered as being amongst Ahlul-Qiblah, and they are those who pray in the direction of the Ka’bah in Mecca. This is the Qiblah (direction of prayer) of the Muslims. We behave towards them based upon what is apparent, and we judge them to be Muslims. We treat them as Muslims, whether living or dead.
والمرجوم والزاني والزانية والذي يقتل نفسه وغيره من أهل القبلة
“This includes the one who is stoned for adultery, the fornicating man and woman, the one who kills himself and other than them from the People of Qiblah..”
The sinful believer who does not exit Islam due to his major sin is dealt with as a Muslim. He is supplicated for, such as the one who kills himself by committing suicide, or the one stoned to death for adultery. The Prophet (salallaahu ‘alaihi wassallam) prayed Janaazah over the one stoned to death; he prayed over the Companion Maa`iz (may Allaah be pleased with him), and over the female Companion Al-Ghaamidiyyah (from the Ghaamidee tribe), may Allaah be pleased with her .
 Muslim, no. 1695 from Buraidah (radiyallaahu anhu).
The Prophet (salallaahu `alaihi wassallam) withheld from praying over some of the people such as the one who committed suicide, and the one who stole from the war booty. This was from the aspect of discipling the people and not due to him considering them to be unbelievers, and for this reason he would grant permission to the Companions to prayer over such a person, and he would not prevent them from praying over him due to the fact that such a person is a Muslim.
والسكران وغيرهم الصلاة عليهم سنة
“..the drunkard and so on – praying the Funeral Prayer over them is a Sunnah.”
The drunkard is the one who drinks intoxicants, a sinner (faasiq), and the Prescribed Punishment (al-Hadd) is established upon him. However he does not exit Islaam – and if he dies, the Janaazah is prayed over him even if he was a consumer of intoxicants due to the fact that he was from Ahlul-Qiblah.
“…is a Sunnah.”
Meaning it is from the Sunnah of the Messenger (salallaahu `alaihi wassallam) which one is obligated to follow.