Where do gamma ray photons come from?
Standing in a lake, I can make a ripple in the water by moving my hand. But this wave wasn't in the water before I did that, and it certainly wasn't inside my hand either.
So where did the ripple come from? We can say it was formed by the interaction between my hand and the water. On a slightly deeper level, it was created from the energy in the muscles that moved my hand, which came from the food I ate earlier.
The same principle goes for gamma ray emission from an atomic nucleus. The charges in the nucleus are making ripples in the electromagnetic field, but those ripples weren't 'inside' the nucleus beforehand. The energy used to create them was, though.
This kind of thinking is necessary to understand more than just gamma ray photons. For example, in beta decay, a neutron turns into a proton, and electron, and a neutrino. None of these three objects were 'inside' the neutron to begin with. (We've smashed particles together to check this.) Instead, one should think of the neutron as a ripple in a quantum field that makes ripples in other quantum fields, in the same way that a hand makes waves in water.
"A photon appearing from nowhere"
The wording suggests to me that you're expecting some properties to be conserved, i.e. not changing over time. And indeed, many physical quantities are indeed conserved. A particle appearing from nowhere would definitely violate that. Let's look at a few of those conserved quantities: energy, impulse, electric charge.
A photon definitely has energy, but your gamma photon was created by a nuclear process. This literally is nuclear energy; the original atom nucleus had a higher energy than the resulting nucleus.
A photon also has impulse. Unlike energy, impulse is a vector. You'll see the resulting nucleus recoil after emitting a gamma photon - it gets an impulse change in the opposite direction. The total impulse is still conserved; the two impulses add up to exactly zero.
Finally, electric charge is the simplest of all: a photon simply has no electric charge, so this is yet another conserved quantity.
There are more conserved quantities, but in the end the conclusion is simple: a photon is just a particle with a few properties, and all those individual properties can be accounted for.
Photons are created by charges changing orbital state, or being accelerated. In an atom, this can mean electrons making a transition between energy levels (and that is where most visible light, and even X-rays, originate. It can also mean that the protons in a nucleus have made a transition between energy levels, and that process produces gamma rays.
Nuclei are very tightly bound, all charges close together, so the energy levels are higher than those of an atom's electrons. To disturb the nucleus usually requires
a nuclear decay event, or very high energy collisions (such as produced
by a particle accelerator). Nuclear energy levels give a predictable
set of spectrum lines, just as atomic (electron orbital) energy levels do.
So, after a nuclear disturbance occurs, the nucleus (or daughter nuclei) will
typically be in some state other than the ground (stable) state.
The excited state decays by emitting one or several photons, which
are called gamma rays.