"The five women had been arrested as suspects after two women were killed last night," National Security Ministry spokesman Mohamed Osman told Anadolu Agency.
"While our officers were taking them to the station, one of our soldiers opened fire, killing all five [suspects]," he said.
Police in Tayeglow, a small town in southwesternSomalia, believe the women were married to Al-Shabaab militants and had been used to convey information that had led to the killing of two women on Tuesday night.
An Al-Shabaab gunman is said to have snuck into Tayeglow in order to kill the two women.
"One of the women killed Tuesday night is the wife of the soldier who killed the five suspects today," Osman told AA.
"The second woman is a Somali National Army officer," he said.
Tayeglow was recently captured by Somaligovernment forces and African Union peacekeepers. Since then, Al-Shabaab has repeatedly tried to recapture the flashpoint town.
Somalia has remained in the grip of on-again, off-again violence since the outbreak of civil war in 1991.
Earlier this year, the country had appeared to inch closer to stability after government troops and African Union forces – deployed in the country since 2007 – drove the Al-Qaeda-linked Al-Shabaab from most of its strongholds.