The mass of the galaxy (mostly in the form of dark matter) is in a roughly spherical blob. So if you look at mass, the galaxy isn't a disc, it is a spheroid. But Dark Matter is invisible, and what we can see (stars, gas etc) is in a disk.
The reason that Dark matter and the normal matter behave differently is that when gas flows there is "friction" (Dark matter doesn't interact with itself or normal matter). This causes the gas to heat up, and that heat energy is then released (as infra-red, light and so on) This means that over time the gas in the galaxy will tend to fall to a lower level. However the gas also has angular momentum (it is rotating), and angular momentum must be conserved (it can't be radiated away like energy). So the gas will try to fall into a low energy configuration that can maintain angular momentum. The shape that achieves this is a disc.
Any gas clouds that are not orbiting in the plane of the disc will hit it, and over time they will be pulled into the same disc.
Gas clouds produce stars, and so most stars will also be in the plane of the disc. Very old clusters of stars in globular clusters however can be found in a spherical pattern around the disc.
So galaxies form disc shapes because the gas that makes stars falls into a disc shape.
However, not all galaxies are discs. When disc-shaped galaxies collide, this can disturb the orbits of the stars, and you get a galaxy which is "blob" shaped, these are called elliptical galaxies, and are very common. Small galaxies also often don't have a disc structure either. These are called irregular galaxies.