g = GM/r^2 is the gravity field, as in PE = mgh, where R - r >= h is the height above r, the radius of the source mass M (e.g., Earth). R is the radius struck from the center of the source mass to the location of the target mass having the potential energy.
Work done on the mass, m, in lifting, is found from dPE = m d(gh) = m (dg h + g dh) = m (2GM/r*h + GM/r^2 * dh) = m [2GM(R - r)/r + GMdr/r^2)] = m [2GM(R/r - 1)] as dr = 0 since r is the radius of the source mass and it's assumed fixed.
And there you are. When R < r, so that R/r < 1.00 and (R/r - 1) < 0, the change in potential energy goes negative. That is, negative work is done; work done by the target mass as it falls below the surface of the source mass.
So as h goes inside r, the PE decreases in value (i.e., work done by the mass). Note, the starting point, mgh, has not changed, but the direction of the PE change has as h < r gets farther away from r, the source mass radius.