They say Tim Kretschmer, aged 17, gave the warning in a chatroom before the killings in Winnenden on Wednesday.
Kretschmer killed 12 people in the school and three others in the nearby town of Wendlingen. He then shot himself after a shoot-out with police.
Police say chatroom users did not take the comments seriously at the time.
At a news conference, Baden-Wurttemberg's Interior Minister Heribert Rech said the gunman had spoken of his attack in a chatroom on a German internet portal.
He said the message read: "I've had enough. I'm fed up with this horrid life... Always the same. People are laughing at me... No-one sees my potential... I am scared, I have weapons here, and I will go to my former school tomorrow and then I will really do a grilling."
The message then continued: "Possibly I get away, so keep your ears open, you will hear from me tomorrow. Just remember the name of the place, Winnenden."
Mr Rech said a German man alerted police about the internet warning after the school shooting.
The man said his teenage son told him about the warning only after seeing the news reports. He had not previously taken the threat seriously.
Officials say Kretschmer fired more than 100 shots during the attack on his former school.
They say he still had more than 130 rounds of ammunition left when he was cornered by police and shot himself.
Prosecutors say they may charge Kretschmer's father for failing to secure the gun used by the teenager in the attack.
Flags are flying at half-mast across Germany on Thursday as a mark of respect for the victims of the shootings.
source (with video)