The officer first shot and killed his wife at their home before setting off with his service-issued AK-47 rifle to shoot dead another four people, the Directorate of Criminal Investigations said on Twitter.
It described the shooter as a "rogue officer".
Francis Wahome, the officer in charge of Nairobi's Dagoretti area, said another two people had been wounded in the incident. He declined to comment on what prompted the shooting.
"The investigations are a secret. We cannot divulge, as it involves many things," he told reporters.
"Until now, we never had any concerns about the officer's behaviour. He had been going for duty properly, and had never been involved in an incident like this."
Three of the men who were killed were mourners who had just attended preparations for a funeral, the DCI said.
Dagoretti resident Lameck Alaka said that before the shooting started, a car he believed belonged to the police drove past them and stopped for about 20 minutes.
"Then he got out, and we saw it was Mr. Ben. He came out with an AK-47, cocked it and started firing at us where we were with the boda boda (motorcycle) riders," he said, referring to the officer by his first name.
Alaka said later other motorcycle riders came running to him saying the officer had killed two other men.
"They said the shooter wasn't speaking; he was just shooting, and we know it is a police officer," he said.
Angry residents near where the incident took place later set fire to tyres on a road in a protest against the violence, a Reuters journalist said.
(Reporting by Monicah Mwangi, Humphrey Malalo, Baz Ratner and Edwin Waita; Writing by George Obulutsa; Editing by Angus MacSwan) Yahoo News/Reuters