The 28-year-old suspect named Luca Traini was driving to the gym and listening to radio news "about the 18-year-old girl" before deciding to "kill them all", according to local media which quoted him as telling investors.
Traini's rampage took place during a court hearing upholding the pretrial detention of Innocent Oseghale, a Nigerian immigrant accused of killing and dismembering 18-year-old Pamela Mastropietro, stuffing her body parts in two trolleys and dumping them in the countryside.
On Saturday, Traini shot and wounded six African immigrants in what the authorities described as a racially motivated attack in the southern city of Macerata.
After the shooting, he drove to a monument, gave the Fascist salute, wrapped himself in the Italian flag, and awaited arrest, local media said.
Macerata Mayor Romano Carancini would not say whether the two events were related and called on everyone to calm down.
"We were shocked by what happened to Pamela, but this does not justify hatred and feeding hatred," Carancini told local media. "Whether or not you agree with the government's immigration policies, we must not stoke violence."
The police officers who raided the home of Traini's mother found far-right literature, including a copy of Adolf Hitler's manifesto "Mein Kampf" and a book by fascist dictator Benito Mussolini.
In 2017, the shooter ran for local office as candidate of the Northern League, a right-wing anti-immigrant party.