A local military court handed down the death sentences to the five men who were arrested in a security operation in the city of Bosaso.
The operation was launched after Islamist militants overran a military base in the region in June 2017, killing dozens of people in the village of Af-Urur.
The executed men were aged between 19 and 39 years old.
The judge at the regional military court, Awil Ahmed Farah, said one of the men was an IS militant who was convicted of killing a police officer.
“I want to confirm that being a terrorist means… a death sentence”, he said when asked why the other four were arrested.
“Killing someone in Mogadishu or in Bosaso is the same”, he said. “They admitted that they have fought in Mogadishu and killed people,” he added.
Another four men accused of being part of al-Shabab Amniyaad – a wing of the group that carries out assassinations and suicide attacks – also separately appeared in front of a military court in Somalia’s capital,Mogadishu.