The sentences for the men, only two of whom are currently in custody, were delivered in the capital Tunis on Friday, spokesperson Sofiene Sliti told AFP.
The other 39 convicted remain at large, he said, adding that all of the those found guilty were linked to the Islamic State group.
Tunisian courts continue to issue death sentences despite no executions being carried out since 1991.
The gun and rocket launcher assault on army positions in July 2014 left 15 troops dead in the Mount Chaambi area of the western Kasserine region that remains a hideout for militants.
The attack was the deadliest ever against the country's army.
Tunisian armed forces have for the past six years carried out operations to track down wanted militants in the area, which was declared a closed military zone in 2014.
'Terrorist attack' kills six Tunisia security forces
Okba Ibn Nafaa, a Tunisia-based division of Al-Qaeda, is also present in the area.
Since its 2011 revolution, Tunisia has experienced an increase in jihadist attacks that have killed dozens of members of the security forces and at least 59 foreign tourists.
Tunisia tour operator first Jewish minister in decades
The country has been under a state of emergency since November 2015, when an Islamic State-claimed suicide bombing in Tunis killed 12 presidential guards.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ