My question is that why does g = 0 when the body reaches surface.
It doesn't! $g$ is the magnitude of the gravitational field of the planet (Earth, in this case). It is $$
|\vec{g}|\simeq\frac{Gm_E}{r^2},$$
where $m_E$ is planet's mass, and $r$ is the distance from the center of the (spherical) planet. At Earth's surface it is approximately 9.8 m/s$^2$, all the time. It just so happens, because of how gravitational forces work, that "the acceleration due to gravity only " ('only' is a key word that gets left out) has a magnitude equal to $g$. (This, IMHO, is one of the big failures in physics pedagogy nomenclature.)
Notice that the graph axis is not showing $g$. It is showing the acceleration, and that results from the net force at the particular time, not merely the gravitational force.
The gravitational field is always present, exerting a force on the mass. But there may be other forces. The acceleration is the result of the net force.