MEXICO CITY — State police have detained and disarmed the entire police force of a town in western Mexico where a mayoral candidate was killed on Thursday.

Video of the detention aired by local media showed uniformed officers hitting each other as gunshots go off in the background.

The Michoacán state police force said, "All the officers of the Ocampo municipal police force were detained for an internal affairs investigation."

In statements on its Twitter account Sunday, the state police department did not directly tie the detentions to the Thursday killing of Fernando Ángeles Juárez, the mayoral candidate for the leftist Democratic Revolution Party. He was killed in Ocampo, Michoacán, on Thursday.

Mexican soldiers guard the funeral of Ocampo mayoral candidate Fernando Ángeles Juárez on Thursday. Raul Tinoco / AFP — Getty Images

Ángeles Juárez is just one of at least 18 candidates killed so far in campaigns leading up to the July 1 elections. Just last week, another mayoral candidate was also gunned down in the conflict-ridden rural town of Aguililla in Michoacán.

Michoacán Gov. Silvano Aureoles vowed to catch those responsible for killing candidate Omar Gómez Lucatero.

Almost all of the 18 candidates killed across the country so far have been running for local posts in the July 1 elections, which will also decide the presidency, governorships and Congress. Other politicians who were considering a run have been killed before they could even register as candidates. The killings have particularly hit states like Michoacán, Guerrero and Oaxaca.

The Michoacán police department did not directly tie the arrests to the killing of Ángeles Juárez. Ivan Villanueva / EPA

Mexican security analyst Alejandro Hope said that in part, the level of violence against candidates can be explained by “simple mathematics”: There are far more elections being held simultaneously than ever before in Mexico. With more than 3,400 local, state and federal posts at stake, there are more than 15,000 candidates hitting the campaign trail.

“Secondly, this speaks to the changes in criminal groups,” Hope said, noting that drug cartels have expanded into extortion, fuel theft and other crimes. “With the evolution of crime, it becomes much more important to gain control over territory, over local governments.”

In crimes like fuel theft, for example, local police can be valuable allies to act as lookouts or cover up for illegal pipeline taps and illicit fuel warehouses. And some gangs have even taken to extorting money from local governments by forcing them to sign inflated public works contracts.

Those concerns could lead the gangs to kill a candidate who rivals their favorite, or to kill candidates who refuse their demands.

Finally, Hope noted, “there has been a breakdown in the management of disputes,” largely in rural areas, where turf wars between rival gangs have heated up, even as the government has become overextended and less able to intervene.

FOLLOW NBC LATINO ON FACEBOOK, TWITTER AND INSTAGRAM.