On one hand, Mary Warren turns against Proctor because of her own capitulation to Abigail and the girls. It becomes evident that Mary needs the affirmation of the group at greater cost than what the truth might be. The fundamental issue that Mary Warren wrestles with is that she is coming clean in terms of being honest about the girls' doings in the woods and the accusations in the form of court testimony. Mary Warren is vitally important because she is the only one who can give clear evidence to what the girls were doing. Proctor knows this and because of it, Mary becomes vital to his motivation of attempting to reject Abigail's claims in court. When Mary contradicts Abigail and the girls, telling the truth in the process, it becomes evident that she has distanced herself from the group. It is here where they become merciless in pretending to be afflicted with a curse of Mary's doing and the other girls' mocking her. In this, Mary, in her emotionally weakened state, makes the call to side with the girls, even thought she knows that in doing so, she is repudiating the truth. In the end, I think that her motivation of turning against Proctor is out of the fear that she does not want to be alone. The expulsion from the group was too much for Mary to bear and in this, she turns against Proctor.
Mainly Mary goes back to the side of the girls because the girls began to fake attack from Mary Warren's spirit in the form of a bird in the rafters. The courts immediately believe Mary Warren is indeed sending out her spirit to attack the girls. Mary Warren could then be hanged as a witch. Plus, the courts are obviously anti-John Proctor, so she's taking the safest, easiest route.