He co-operated with officers and there were not enough grounds to take away his gun at the time, police said.
The 35-year-old suspect, named only as Philipp F, had a licence to own the weapon for sporting purposes.
The country is preparing a new law involving tighter curbs on gun ownership, the interior minister said.
Seven people, including an unborn baby, were killed in Thursday's attack which unfolded at a Jehovah's Witness meeting hall in the city.
The first emergency call came at 21:04 local time (20:04 GMT) to report that shots had been fired, and officers were on site four minutes later.
Video appeared to show the gunman firing through a window. He then stormed the building where dozens of people had gathered, firing nine magazines of ammunition before apparently turning the gun on himself after police arrived.
Eight people were injured, including a woman who was seven months pregnant. She survived but her unborn baby was killed.
Chancellor Olaf Scholz said the death toll could rise.
German Senator Andy Grote said "fast and decisive actions" by police officers saved many lives. He described the attack as the "worst crime" in Hamburg's recent history.
Officials said the suspect had "ill feelings" towards the religious community, of which he had previously been a member before leaving "on bad terms".
Jehovah's Witnesses are members of a Christian-based religious movement, founded in the US at the end of the 19th Century.
In its latest report from 2022, the movement says there are about 8.7 million Jehovah's Witnesses worldwide, including about 170,000 in Germany. In the city of Hamburg, there are believed to be nearly 4,000 members.
On Friday, Hamburg Police Chief Ralf Martin Meyer said officers visited the man in February after they received an anonymous letter claiming he "bore particular anger toward religious believers, in particular toward Jehovah's Witnesses".
The letter also said he "might be suffering from a mental illness, although it had not been medically diagnosed".
Police said he was co-operative and had an open conversation with the officers. "The bottom line is that an anonymous tip in which someone says they're worried a person might have a psychological illness, isn't in itself a basis for [such] measures," Chief Meyer said.
Forensic experts worked at the scene of the shooting on Deelböge street through the night but have since left the area.
Mourners have left floral tributes near to the front door. One man, holding his little boy and girl by the hand, told the BBC he tried to come home last night but his way was blocked by police wielding assault rifles.
Germany already has some of the strictest gun laws in Europe, including a clause that anyone aged under 25 must pass a psychological evaluation before getting a licence.
In 2021, there were about one million private gun owners in Germany, according to the National Firearms Registry. They account for 5.7 million legal firearms and firearm parts, most of them owned by hunters.
After mass arrests were made last December in relation to a suspected plot to overthrow the government, the German authorities have been under pressure to tighten the country's gun laws even further.