There are two ways to create gamma rays from a black hole, and the two are distinguished by the size of black hole that creates them. The first is called a Gamma Ray Burst, and is sometimes formed during the creation of a “stellar mass” black hole, as a star collapses at the end of its life. Gamma Ray Bursts are the most intense bursts of gamma radiation in the universe, but are pretty rare and therefore hard to spot. These bursts happens over the period of less than a minute - incredibly short, especially given the lengthy timescales that astronomy usually operates on. They are created during what’s called a hypernova - the amped up cousin of a supernova, where the original star is at least 15 times the mass of our sun. In addition to the high mass of the star, in order to get the gamma rays out, you also need to have the star rapidly rotating before it explodes & collapses.
The second way that black holes can produce gamma radiation is via objects we call quasars - an abbreviated form of a “quasi-stellar object”. This is a remnant from the days in which we kept finding these super bright, point-like objects (like stars) but had really bizarre spectra (definitely not like stars). They were dubbed “quasi-stellar” in nature due to them looking like a star, but not behaving like a star. We now believe that quasars are the signature of supermassive black holes at the centers of galaxies that are currently attempting to grow by inefficiently pulling in material from a rapidly spinning disk of material that surrounds the black hole.
The formation of gamma rays in both Gamma Ray Bursts and in quasars occurs in a very similar manner. For a Gamma Ray Burst, the rapid rotation of the dying star twists up the magnetic field of the dying star, and means that the easiest means of escape for any of the particles being produced in the supernova is along a very narrow ‘beam’ at the poles of rotation, since the magnetic field can’t get as tangled in that direction. However, many of the particles being given off are electrons, not photons; getting from a beam of electrons to a beam of gamma ray photons requires a few transfers of energy. There are a couple of ways of doing this. One method of energy transfer happens when electrons travel along the untangled magnetic field lines extending outwards along the beam. The magnetic field causes the electrons to travel in a helix, as though they were tracing the path of an extremely long spiral staircase. These spiraling electrons give off high energy particles of light; if the electrons are moving fast enough, they can spit out gamma rays. The other way you can create gamma ray photons is more straightforward: via collision. If you take a extremely speedy electron and crash it into a photon, the photon can gain enough energy to become a gamma wave. The end result of both of these processes is a pencil beam of gamma radiation speeding outward in two jets at the north and south poles of the spinning star. These jets are only stable for a few tens of seconds before the black hole forms, and they vanish.
Getting gamma radiation out of a quasar happens in a very similar way to the Gamma Ray Burst. We believe there must be a magnetic field surrounding the disk of material surrounding the black hole (called the accretion disk), and this disk must be rapidly rotating. The black hole itself may also be rapidly spinning, but that depends on which theoretical physicist you speak to. The rapid spin of the accretion disk, in combination with the magnetic field, produces jets, which can accelerate particles (again, largely electrons) all the way up to gamma ray energies. These quasar jets, in contrast to those produced by Gamma Ray Bursts, are very stable, and can reach lengths of hundreds of thousands of light years. If we are able to spot them, it means that that quasar just so happened to have been aimed in our direction as it shot a bright beam of light across the cosmos.