My kids both had a period of time where they sleep walked. My husband and all his siblings, did, too. (My husband when he was about 8, sleep walked over to his closet and peed in the closet, on the shoes. He really thought he was in the bathroom!)
There can be a genetic component to sleep walking. And your son really has to go to the bathroom but isn't all the way awake.
Locking him in his room will only give him night terrors and make him afraid to go to sleep---don't do it. His body feels the need to get up but his mind isn't awake.
Instead, try to find the cause: school issues, friends, issues, look at nutrition. Is he getting too much activity or not enough exercise early in the day?
When my youngest was sleep walking when he was 11, we reduced sugar, eliminated caffeine and all red/ pink / blue colored foods and drinks. That helped a lot. He had changed schools which was stressful and started a new sport...where all the kids drank red or blue Gatorade after practice every day. Those red foods have dyes that some kids react to.
Make these changes without a big deal or too much discussion. You don't want him to feel like he is being "punished" for sleepwalking.
Have a constant, calming bedtime routine that prepares him for sleep. No TV, no video games...nothing like that to keep the brain "charged up." The brain and the body have to relax in order to sleep well. We tried warm bath, 20 min. reading or coloring, quiet music in room for 10 min. before lights out. Make those changes as a family, so your son won't feel isolated. (Yes, this meant my husband had to turn the TV OFF in the evening.) And maybe everyone will sleep better. My husband started sleeping much better when we started reading and turned that tube off weekdays.
Hope that helps!