What happens in a generator so that we get a sinusoidal voltage as an output?
A synchronous generator has a rotating magnetic field that is produced by a permanent magnet or a wound field (electromagnet). The direction of the magnetic field is such that the stator conductors pass through the flux of each pole as the rotor turns. It is the reversal of flux from one pole to the next that induces AC voltage.

For the induced voltage to be sinusoidal, the shape of the magnetic field must be sinusoidal. Designing winding configuration and the poles of the rotor to produce sinusoidal voltage is a complex task that is described in detail in electric machinery text books.