The short answer is that we don't know. The formation of disks on either galactic or planetary scales are extremely difficult to do because they require your simulation to have a huge dynamic range.
The long and crude answer is that the progenitors to these objects (molecular clouds and cosmological overdensities) can be given small torques by the tidal fields of other nearby objects. This causes the entire progenitor to rotate slowly in some arbitrary direction. Then, as it collapses gravitationally, angular momentum must be conserved and the cloud/overdensity begins to rotate more quickly. This rotation produces a strong asymmetry (along the axis of rotation) in the dynamical system. This system tends to conserve angular momentum about the rotation axis, but lose energy to radiative cooling. The net effect is contraction into a disk rotating roughly about the axis created by the original torque.