The attack in Torreon was one of the deadliest in Mexico's drugs war
Gunmen who killed 17 people at a party in northern Mexico earlier this month were let out of prison to carry out the attack, state prosecutors say.
Guards at a prison in Durango state are accused of lending the inmates weapons and vehicles to commit the murders in neighbouring Coahuila state before returning them to their cells.
The same group of prisoners are thought to have carried out other killings.
The prison director and at least two other officers are under investigation.
The killings in the city of Torreon in Coahuila state were traced to Gomez Palacios prison in neighbouring Durango state through bullets found at the crime scene, which matched assault rifles assigned to the guards, attorney-general's office spokesman Ricardo Najera said.
"They were allowed out of prison to kill using the weapons of the guards and travelling in official vehicles" he said.
Mr Najera said the prisoners were acting as contract killers for a drugs gang, and were thought to have carried out two other mass killings in Torreon earlier this year using the same weapons.
"The criminals carried out the executions as part of a settling of accounts with members of a rival organised crime gang. But they also killed innocent civilians in a cowardly manner before returning to their cells."
Investigators are questioning all of the prison guards as well as about half the inmates in the prison.
Coahuila state, which borders Texas, has been the scene of a bloody battle between rival drugs gangs fighting for control of smuggling routes into the US.
The Zetas cartel is being challenged from its former ally, the Gulf Cartel, in an alliance with the Sinaloa cartel led by Joaquin Guzman, Mexico's most wanted man.
The Mexican government says almost 25,000 people have died in drug-related violence since President Felipe Calderon deployed the army to fight the drugs gangs in December 2006.