Saabaruddin, chief of security guards in the Pidie district capital of Sigli, said today that the men were caught playing dominos for money at a coffee stall in February.
He said the men were detained at a city penitentiary and were convicted by a Shariah court last week.
Saabaruddin, who uses one name, said hundreds of onlookers watched as the men were caned after Friday prayer at Sigli's main mosque.
He said one of the men was caned eight times, while the other four were caned seven times.