This could be a medical problem... our bodies make a chemical that tells us we need to wakeup to go to the bathroom. If that's the case, there's a simple pill he can take to add this chemical to his body... it worked wonders for my sisterin law.
It could also be an emotional issue. Perhaps a bully is picking on him, or it's his way of coping with stress... in which case, a pediatrician can recommend a counselor. The counselor can help give him the tools he needs to cope with stress.
Remember, a 9 year old has stress... it doesn't seem like stress to us because we have the tools to cope with those things as well as larger perspective.
Unless your child is unusually defiant, this isn't about misbehaving, it's about a problem to be solved.
I'd start by saying, "You know what? I think I've misunderstood. I thought you were misbehaving when you'd have accidents. I'm sorry I thought that, and I'm sorry if I hurt your feelings. Now I think I was wrong, and that there's a problem we don't know about. So I scheduled an appt for you at our kid-doctor. You don't have to be afraid, he won't hurt you. He'll help us solve this problem!
Good luck!