You get a disk when the particles lose energy (often by radiating it away) but keep their angular momentum. It's generally much easier for energy
Galaxies are made of stars, but the stars are born from clouds of gas. The gas has many ways to be transportedradiate energy away than for angular momentum, which can cause it to settle into a disk. The stars may then be transported awayformed in the disk structure.
Not all galaxies are disks, though, many are spherical. As you say, it's not a simple problem and it depends sensitively on the initial conditions.