When your child is away from home does he do the same thing. If not, he wants Attention.....tell him if he does it again he can either change is own underware or stay the way he is because he knows beter and you are not going to do anything about it. My grandson was doing the same thing. That's how they found his diabeties. His younger sister started wetting her self and wetting the bed. She stopped after her mother explained what was wrong with her brother and she was old enough to know she controlled her own bladder. Just a suggestion.
Let him drink plenty during the day cut back in the evenings on all liquid , has he recently stared a new school/day care sometime s teachers are busy and forget to tell children to go to the bathroom, Has there been any new happening in his life new sibling, new house , family around or not around ?he may be upset about something, Good Luck
Have you taken him to the doctor to check for an infection.
My son sometimes does this but if he does it at night it is usually because he has drank something an hour or so before bed. I will sometime set him on the potty and tell him to go he will and he really isn't awake I leave a nite lite on so its no so bright. He goes right back to sleep. Or if he is playing he forgets to go. I will usually ask do you have to go.