Imam al-Shafi'i (may Allah have mercy on him) said: "The Messenger of Allah (peace and blessings be upon him) carried out the prescribed punishment (hadd) in Madinah, although shirk (that is, the polytheists) was close to it, and in Madinah itself there were many polytheists with whom there was a peace treaty; and he (peace and blessings be upon him) had the drinker (of wine) beaten (as the hadd) at Hunayn, while shirk (the polytheists) was close to him."
Sayyiduna Abd al-Rahman bin Azhar (may Allah be pleased with him) said: I saw the Noble Messenger (peace and blessings be upon him) on the day of Hunayn asking about the camp of Sayyiduna Khalid bin al-Walid (may Allah be pleased with him), when a drunk man was brought. He (peace and blessings be upon him) said to the people: "Strike (him) with whatever is in their hands," and the Messenger of Allah (peace and blessings be upon him) threw dust on him.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب السير / 18217