The answer is turbulence. Stars are formed from large gas clouds that collapse under their own weight. As they do so, they become unstable to fragmentation and break up into smaller collapsing pieces. Turbulence in the original cloud means that each of these pieces has its own individual angular momentum and rotational energy, even if the total angular momentum of the original cloud was zero. The original turbulence can be injected in many ways, including gravitational interactions and collisions with other clouds, the tidal effects of the galaxy, shocks from supernovae, the winds of massive stars, etc.
As the collapse proceeds, dissipative interactions in the collapsing cloud cause it to radiate away energy, but very little angular momentum. Both quantities must be conserved, so the system tends towards a configuration with minimum energy for a fixed amount of angular momentum - which is a rotating disk.
In order to accrete into the central protostar, the material in the disk has to somehow lose angular momentum in order to fall inwards. It does this by transferring angular momentum outwards through various viscous processes. Ultimately though, some of the disk material has to escape with the angular momentum to allow some of the material to accrete into the star. There are a number of processes that can achieve this including "disk winds" and photoevaporation.