The flag was found in the room of the man who seriously wounded four people and injured several others on a regional train in the city of Wuerzburg, Bavaria state interior minister Joachim Herrmann told ZDF public television.
The teenager was shot dead by police as he tried to flee.
Earlier, Herrmann had said the assailant had arrived as an unaccompanied minor in Germany and had lived at first in a shelter and then more recently with a foster family in nearby Ochsenfurt.
A spokesman for the interior ministry had said it was “quite probable that this was an Islamist attack”.
However he stressed that the investigation was ongoing and that the teenager appeared to have acted alone.
The attack happened around 9:15 pm (local time) on Monday on the train running between Treuchlingen and Wuerzburg in Bavaria.
PTI