Answer: The black holes you’re thinking of are known as supermassive black holes. Stellar mass black holes are created when a star at least 5 times larger than the Suns out of fuel and collapses in on itself forming a black hole. The supermassive black holes, on the other hand, can contain hundreds of millions of times the mass of a star like our Sun.
Astronomers are now fairly certain that these supermassive black holes are at the heart of almost every galaxy in the Universe. Furthermore, the mass of these black holes is somehow tied to the mass of the rest of the galaxy. They grown in tandem with each other.
When large quantities of material falls into the black hole, it chokes up, unable to get consumed all at once. This “accretion disk” begins to heat up and blaze brightly in many different wavelengths, including X-rays. When supermassive black holes are actively feeding, astronomers call these quasars.
So how do these black holes get there in the first place? Astronomers aren’t sure, but it could be that the dark matter halo that surrounds every galaxy serves to focus and concentrate material as the galaxy was first forming. Some of this material became the supermassive black hole, while the rest became the stars of the galaxy. It’s also possible that the black hole formed first, and collected the rest of the galaxy around it.
Astronomers just don’t know.