A 17-year-old suspect was detained after opening fire at a Hat Yai school with a firearm stolen from a police officer.