SAN DIEGO — A man with a long history of mental illness has been sentenced to 25 years to life in prison for beating a man to death at a San Diego County jail.

The San Diego Union-Tribune says 25-year-old Joshua McDaniels was sentenced Thursday for first-degree murder.

The San Diego man told investigators he was hearing voices when he punched and stomped 69-year-old Frank Fernandez in a holding cell in 2015.

McDaniels had been arrested that morning after he was seen running naked in traffic. Tests later found amphetamine in his system.

Fernandez, who had dementia, had been jailed for being drunk in public.

The judge said McDaniels was in a psychotic state during the attack but knew he was doing wrong and thus didn’t meet the legal definition of insanity.