I went through this with my daughter. It wasn't wetting her pants - she would drop her pants and squat on the floor. She wanted clean clothes, but didn't want to go to the bathroom. This started at about age four, but continued until she was 9. It was awful.
By that time it had become an extreme battle of wills. She kept doing it just to prove to us and herself that she would do whatever she wanted, regardless of what we said or did. (And no matter how we cleaned the carpet, the smell never quite went away.)
With her, it was a combination of not wanting to interrupt what she was doing to go to the bathroom and just plain acting out. Having to stop what she was doing to go into the bathroom annoyed her. Plus, this particular child was always my boundary pusher, always trying to see what she could get away with and what we could and would do in response.
We tried dozens of things, and finally did what author/lecturer John Rosemond calls, "kicking the child out of the Garden of Eden." We emptied her room of everything except clothes and her furniture. All her toys, books and games were given away. We chose one weekend and told her that she would spend the entire weekend in her room, except for meals and bathroom visits. Since we had church and a family dinner at her aunt's house on Sunday, she actually only spent Saturday in her room. It was the longest Saturday any of us have ever spent, and we agonized over whether it was the right thing. It must have been, because after 5 years the behavior FINALLY stopped.
She's an adult now, and a bright, funny, talented woman, but your letter reminded me that it was a long road getting there! ;P