If the energy of the photon is conserved along a geodesic why is it redshifted

This is a good question and it tests ones understanding of red shift owing to gravity. The summary of what I am about to say can be stated as follows:

the gravitational red-shift of light can best be seen as a statement about the differing rates of clocks at different locations.

Now I will unpack this. The statement about conservation can be put in two (equivalent) ways.

  1. If the metric is independent of time (in the chosen coordinates) then $p_0$ is conserved along a geodesic, where ${\bf p}$ is the 4-momentum of the particle concerned (whose worldline is the given geodesic).

  2. If the vector field $\bf K$ satisfies Killing's equation (that is to say, it is a Killing vector field) then ${\bf K} \cdot {\bf p}$ is constant along the worldline of the particle.

In view of this conservation, the term "energy" is widely applied to the quantity $p_0$. The energy (defined this way) of a photon is everywhere the same along its geodesic, in a stationary spacetime.

However, this "energy" is not necessarily the one which an observer will observe. Suppose an inertial observer whose 4-velocity is ${\bf u}$ carries some sort of energy-detecting device. When they measure the photon with 4-momentum $\bf p$, the energy they will observe in their own frame is given by $-{\bf p} \cdot {\bf u}$. (If you prefer index notation, then you can use $-{\bf p} \cdot {\bf u} = - p_\mu u^\mu$; and I am using metric signature $(-1,1,1,1)$.)

Now consider two such observers at different locations, and suppose the spacetime is stationary and they are both at rest relative to the coordinates. They will not necessarily have the same $u^0$. In fact, they usually will not if the metric is different at the two locations. For we have $$ u_\mu u^\mu = -c^2 $$ so $$ g_{\mu \nu} u^\mu u^\nu = - c^2 $$ for either observer. Hence if $u^i = 0$ (spatial part zero, so observer not moving relative to the coordinates) then $$ g_{0 0} (u^0)^2 = - c^2 \;\;\; \text{(no sum)} $$ hence $$ u^0 = \sqrt{ - c^2 / g_{00} } $$ Let the two observers be A and B. We have $p_0$ is the same at A and B. So the observed energies are $$ E_{\rm A} = -p_\mu u^\mu_{\rm A} = -p_0 u^0_{\rm A} = -p_0 c \sqrt{-1/g_{00}(A)} $$ $$ E_{\rm B} = -p_\mu u^\mu_{\rm B} = -p_0 u^0_{\rm B} = -p_0 c \sqrt{-1/g_{00}(B)}. $$ Hence the ratio of these observed energies is $$ {E_{\rm B} \over E_{\rm A}} = \sqrt{ g_{00}(A) \over g_{00}(B) } $$ This is the gravitational redshift in the case of a stationary spacetime.

Overall, what is happening is that the two observers look at a light wave having some $p_0$ which is the same everywhere, but they interpret this as differing frequency when compared with their own clocks, and differing energy similarly.

Further remark

Components of 4-vectors (or higher rank tensors) are always frame-dependent. In SR this fact does not perturb our physical intuition too much. This is because the components correspond closely to what some inertial observer will observe. But in GR the situation is different because of the great generality of the coordinate choices available, and the possibility that spacetime itself may be dynamic. In GR this implies that no component (of any 4-vector or higher rank tensor) should ever be attached too strongly to a physical concept. For example, $p_0$ is energy-like, and so is $p^0$, but both will change in odd ways if you adopt an unusual coordinate system, or if the spacetime is not stationary in the first place.

The situation of a stationary but non-flat case is intermediate between SR and the full generality of GR. Here one may, with caution, talk as if some component or other corresponded to a concept such as energy or momentum, especially when there is a conservation. So this is why $p_0$ (or $-p_0$) earns the right to be called "energy", but $p^0$ does not. But I would insist on those inverted commas. To get something straightforwardly called energy, consider what an inertial observer at some given event would observe. That is given by $-{\bf p} \cdot {\bf u}$ as explained above.

The answer by Michael Seifert to a similar question is a literal answer to your question. However, you're saying that the following conceptual issue is still confusing you:

But Caroll says that though the geodesic eqn (or rather by just solving the Euler Lagrange eqn for the time coordinate) you have $(1−R/r)\dot{t}$=constant and the constant is interpreted as the energy. So I understand that energy is conserved along a geodesic and hence the question of photon getting redshifted and loosing energy.

When a spacetime has a Killing vector, we get a corresponding conserved quantity for test particles. When the Killing vector is timelike, we say loosely that this is interpretable as a conserved energy, but this is just a loose interpretation. Actually the fit with newtonian notions of energy is not very close. And in any case, it can't be the energy that would be measured by any observer whatsoever, because that depends on the motion of the observer.

RedGiant says:

Do you know that energy conservation law does not hold in GR?

This is wrong as applied here. GR has no global conservation of the energy in an entire spacetime (except in special cases like asymptotically flat spacetimes), which is a completely different statement. Here we're talking about a conserved quantity for a test particle.

The answer by stuffu is also wrong. The conserved energy of a test particle in a stationary spacetime cannot be described in terms of newtonian concepts like kinetic and potential energy. There is a nice discussion of this sort of thing, at an elementary level, in Taylor and Wheeler, Exploring Black Holes, p. 3-19.

Stuffu says:

In an accelerating frame there is a potential field.

This doesn't make sense. These words don't mean anything in relativity.