The incident injured at least 54 people, mostly students.
Witnesses told local television stations that they heard at least two loud blasts around midday on Friday, just as the sermon had started, from inside and outside the mosque at SMA 72, an Indonesian state high school.
Students and others ran out in panic as grey smoke filled the mosque.
Police said they had recovered a toy submachine gun belonging to the suspect and inscribed with what appeared to be white supremacist slogans.
However, they brushed away speculation that the blasts were a terror attack.
"The suspect is a 17-year-old male student" who was undergoing surgery, Deputy House Speaker Sufmi Dasco Ahmad told reporters after visiting victims at a hospital.
Police confirmed they were looking into reports in local media that the suspect was a grade 12 student who had been bullied and wanted revenge by carrying out what was intended to be a suicide attack.
"We are still investigating the possibility that bullying was a factor that motivated the suspect to carry out the attack," Jakarta Police's spokesman Budi Hermanto told reporters late on Friday.
"There are several obstacles in obtaining information from witnesses as they are also victims who need medical treatment to recover," Hermanto said, adding that authorities are providing "trauma healing" for students and teachers.
National Police Chief Listyo Sigit said the suspect was one of two students having surgery for injuries from the blasts.
"Our personnel are currently conducting an in-depth investigation to determine the suspect's identity and the environment where he lives, including his house and others," Sigit told a news conference at the presidential palace in Jakarta.
Sigit said investigators are still collecting information, including how the suspect was able to assemble a toy submachine gun with words inscribed on it, including "14 words. For Agartha", and "Brenton Tarrant: Welcome to hell".
"14 words" is generally a reference to a white supremacist slogan, while Brenton Tarrant is the perpetrator of a 2019 mass shooting at a mosque and Islamic centre in Christchurch, New Zealand, that killed 51 and injured dozens of others.
"We discovered the weapon was a toy gun with specific markings, which we are also investigating to understand the motive, including how he assembled it and carried out the attack," Sigit said.
Most of the victims suffered burns and injuries from flying glass.
The type of explosives used was not immediately known, but the blasts came from near the mosque's loudspeaker, according to Jakarta Police Chief Asep Edi Suheri.