I think the working theory is that in most cases, people develop DID as a coping mechanism when they experience trauma, particularly as a child. It's a way of keeping traumatic experiences seperated off in the mind.
So, say a child is gets abused by an uncle: when it's happening, they dissociate and create a comparment in their mind to deal exclusively with the uncle. All of the experiences with the uncle get locked awsy safely in that alternate personality. As though the abuse was literally happening to someone else.
The rest of the time, they shut off that comparment completely, so that they can function like any other ordinary kid, without having the disruption of all those traumatic memories and emotions running amok in their mind.
Once a child's mind develops this as a coping strategy, the mind can then decide "Hey, this is an awesome, simple way to be the perfect kind of person in all sorts of situations". So the mind then starts creating new personalities: a personality to deal with high school, a personality to deal with boyfriends, a personality to deal with feeling threatened, etc etc. Each personality is able to deal with its alotted environment perfectly: you can be an awesome girlfriend, then switch automatically into a super-human threat-response person, then back to you, automatically. Cool!
It's pretty clever.
Of course there's glitches in the system, like not being able to acces all your own memories, and not having conscious control of who you are and how you behave from one situation to the next. Which is why we work on getting some degree of integration between the parts as a typical form of DID treatment.
That's just my understanding of the current theories though, and it'd be good to get other interpretations.