The 32-year-old man, who was not identified by name, passed away in a hospital in Baar, Zug's security department said in a statement.
"The individual, who was in full possession of his mental faculties, made a conscious choice to refuse food," the department said.
The man's stated goal was to be released, which was impossible under the law.
"The authorities regret the death of the prisoner," the security department said.
Officials "tried repeatedly to encourage him to take food, and made clear to him the health consequences on multiple occasions," the department said.
"The authorities must implement legal rulings and had no room to meet his demands, as he was considered a danger to others."
The department said he was repeatedly made aware of the legal situation.
"During the entire period of his refusal of food, medical care was provided," it added.
The man could not be force-fed for legal reasons, as well as because of medical ethics specifying that a patient's will is paramount, the department said.
He launched the hunger strike in late January and was hospitalized at the end of February as his condition deteriorated.