If you are asking instead why most galaxies can be placed into two different classifications: spiral and elliptical, I think the general consensus right now is that it has something to do with dust. Spiral galaxies have a lot of dust in them. This dust experiences friction, which, over time, pushes nearly all of the stars in the galaxy into a single plane. The links that Drakkith mentioned are good at explaining why, once the stars are revolving in the same plane, the galaxy ends up with a spiral shape.
As for why the galaxies switch between these two phases, my understanding is that a lot of work remains to really understand what's going on here, but that it's generally expected to be tightly related to the behavior of the supermassive black hole at the centers of these galaxies: when the supermassive black hole gobbles up too much matter, it gets so bright that it heats up the dust in the galaxy so much that most of it gets pushed out. At least, that's what I recall from memory.