The sentenced migrants appeared at a court in Nador, a Moroccan city bordering Melilla, and intend to appeal.
Their representative, Khalid Ameza, could not specify the charges against the 13 when approached by AFP.
According to the official toll, 23 people died when around 2,000 migrants, many of them from Sudan, stormed the fences along the frontier on June 24.
It was the largest death toll in years of attempted crossings into the enclaves.
Spanish rights group Caminando Fronteras says as many as 37 people lost their lives in the mass crossing attempt.
Morocco earlier this month sentenced 14 migrants to eight months' jail following their arrest a day before the deadly mass crossing.
And a Moroccan court last month sentenced 33 migrants to 11 months in jail for illegal entry.
The two Spanish enclaves of Melilla and Ceuta are the EU's only land borders with Africa.