Carry a 10 kg bag of rice up a flight of stairs 3 m high. Whether you take the straight staircase or a long winding ramp, you end up 3 m higher, and the rice now stores mgh=10×9.8×3=294 J more gravitational potential energy than before. That energy came from your muscles, and it would come back as motion (and noise) if the bag fell down the stairwell. The path does not matter, because gravity depends only on vertical position.
Each part of mgh has a job. mg is the object's weight, the force with which gravity pulls it down. h is the vertical height above whatever level you call zero. Their product is the work gravity would do if the object fell back to the zero level. Because the zero is a choice, PE itself can be positive or negative; what has physical meaning is ΔPE=mgΔh, which comes out the same for every choice of zero.
PE=mgh is an approximation that treats g as constant, which holds within a few kilometres of Earth's surface. For a satellite hundreds of kilometres up, g is noticeably smaller, and the correct expression is PE=−rGMm, with r measured from Earth's centre. A quick test: if the height change is tiny compared with Earth's radius of about 6,370 km, use mgh; if it is not, use the general formula.
Think of it like this. A waterslide shows how it works: the speed you reach at the pool depends on how far down you drop, not on how twisty the slide is. A taller slide stores more energy, and so does a heavier rider. Real slides lose a little energy to friction; mgh counts only what gravity stores.
Core idea. Near Earth's surface, raising a mass m through a vertical height h stores mgh joules; only the vertical change counts, and only differences in PE have a fixed meaning.