This is because one mass attracts other mass . Even for small objects like a pencil , your computer.But when you have millions , and even trillions of tonnes of mass , the effect of gravity builds up. So with all of the mass attracting each other, it tries to create the most efficient shape i.e. a sphere .
i hope it helps.
pls mark as best...