For finding potential energy of chain we will have to see its centre of mass height h from the ground.
In figure (a): hc=0⇒Potential energy, U=0
In figure (b): hc=h⇒Potential energy, U=mgh
In figure (a): hc=12⇒Potential energy, U=mg12
Yes, we have to consider the height of center of mass from the reference line to find the gravitational potential energy.