How are quasars formed?
When material falls into the accretion disc of a super massive black hole.
Most galaxies are thought to have super massive black holes at their centres. These black holes have accretion discs which consist of material spiralling into the black hole.
When material falls into the accretion disc is gets heated by friction and gravitational forces. The energy produced by this causes the huge output of a quasar.
A quasar is formed when a super massive black hole at the centre of a galaxy has enough material around it to fall into the accretion disc to generate the energy to power it.
The only galaxies with enough material to create a quasar are young galaxies and colliding galaxies. All nearby galaxies are too old to be quasars unless they collide. Known quasars are very distant galaxies which the light from them has taken billions of years to reach us. We are seeing young galaxies as they were when the Universe was young.
It is quite likely that our own Milky Way galaxy was a quasar in its youth when it had plenty of material falling into the central black hole. It could become a quasar again when it collides with the Andromeda galaxy in about 4 billion years.