Joachim Herrmann, the interior minister of the state of Bavaria, said the flag had been found among the teenager's belongings in his room in his foster home in the nearby town of Ochsenfurt.
In the video, the authenticity of which it was not immediately possible to verify, the man also says he is "one of the soldiers of the Islamic State and will carry out a martyrdom operation in Germany", according to the Arabic-language subtitles.
Four passengers on the train - members of the same family and tourists from Hong Kong - were seriously injured, with one in critical condition, he said.
The 17-year-old started attacking the passengers with an axe and a knife around 9:00pm local time on Monday as the train was approaching its last stop, the Bavarian city of Wuerzburg. But authorities cast doubt on that claim, and said they have not found a direct link between the attacker and the terror group.
"They (police) chased him up, confronted him, the attacker then was very aggressive and attacked the police officers with his ax", Herrmann said. Earlier, German authorities had revealed that investigators had found a hand-drawn flag of the Islamic State in the room of the Afghan teenager, along with notes in Pashto indicating that might have indicated self-initiation.
And police in April arrested two 16-year-olds over an explosion that wounded three people at a Sikh temple, in what was believed to be an Islamist-motivated attack against an Indian wedding party in the western city of Essen.
The claim was posted on the group's Aamaq news agency on Tuesday. In addition to an axe, he was also wielding a knife.
Fourteen people were treated for shock.
Herrmann said people close to the attacker told investigators he had seemed like a calm person, not overtly religious or an extremist.
The train was on its way from the Bavarian town of Treuchtlingen to Wuerzburg, which is about 60 miles (100 kilometers) northwest of Nuremberg.
Witnesses said the carriage looked "like a slaughterhouse", with victims' blood covering the floor. He said people who knew the teen, who came to Germany as an unaccompanied minor two years ago, described him as a devout Muslim, but not "radical or fanatic". He was later sent to a psychiatric hospital.
Germany let in a record almost 1.1 million asylum seekers past year, with Syrians the largest group followed by Afghans fleeing ongoing turmoil and poverty in their country.
Official statements from Germany contradicted the claim of responsibility.