Check with the doctor to rule out any physical reasons first, but it sounds more like emotional reasons reading your post.
Our granddaughter had been totally "housebroke", nights and days (on her own) by 3, then a change in circumstances at age 5 at home, caused a restart of day time and night time accidents. She got a new stepmom, and was given a room all to herself, along with moving to a new house. Too much for her mind to handle all at once. Even though she knew and loved her new stepmom, with the move to a new house, with a room all alone, it was too much stress. Mom and dad kept sending her to the bathroom, or trying discipline, but finally realized it wasn't something she could control. With some counseling for them and her, they decided to just let her be, kept reassuring her that she was doing fine, and would overlook any accidents as "just part of the daily routine", so it didn't make her think she should be "ashamed", etc. She would run in and change if she had an accident, but nothing was said or nothing made of it, and she went back about her business after changing. Within a few short months, things were back to no more problems.
If your son is having accidents at school, make sure he has pants that won't allow others to know, and assure him, he's definitely not alone. This is a very common thing for children.