If you started with a galaxy that is a nearly uniform ball, the gas and bodies near the equator would attract the gas and bodies that are further out.
Those further out would tend to collapse towards the equator and eventually that initial ball would become more disk shaped.
Then there is this explanation refering to the conservation of angular momentum: https://van.physics.illinois.edu/ask/listing/18318