A jury in July found Jarrod Ramos, 41, criminally responsible for the massacre, one of the deadliest attacks on a US media outlet.
In addition to the five life terms, Judge Michael Wachs sentenced the gunman to one life sentence plus 345 years, the prosecutor's office said.
Ramos pleaded guilty in October 2019 to 23 felony counts, including five counts of first-degree murder, but argued that he was not criminally responsible due to a mental disorder. The jury rejected his insanity defense after just a few hours of deliberation.
The mass shooting took place on June 28, 2018, when Ramos walked into the Gazette's Annapolis newsroom and killed the newspaper's assistant editor, Rob Hiaasen, 59; reporter Wendi Winters, 65; editorial page editor Gerald Fischman, 61; sports journalist John McNamara, 56; and sales assistant Rebecca Smith, 34.
Ramos had waged a long legal battle with the paper over a column it published about him, and his lawsuit was eventually dismissed.
The trial had been postponed several times, in part because of the coronavirus pandemic. Had the jury found that Ramos was suffering from a mental disorder at the time, he could have received a sentence committing him to a mental health institution.