It is the first time such social restrictions have been introduced.
The al-Shabab administration said those who disobeyed the new rules would be punished according to Sharia law.
The BBC's Mohamed Moalimuu in Mogadishu says the penalty would probably be a public flogging.
The militant group has already banned music in areas that it controls, which include most of central and southern Somalia.
Somalia has not had a stable government since 1991.
The UN-backed government only controls parts of Mogadishu and a few other areas.