Sufiyan said: "Punish them "refers to unmarried, and "confine them to houses" refers to the women who are married.
In-book : Book 40, Hadith 64
English translation : Book 39, Hadith 4400
40. Prescribed Punishments (Kitab Al-Hudud)
باب فِي الاِسْتِنْجَاءِ بِالْمَاءِ