Intuition for the negative sign of gravitational potential energy The gravitational potential energy is introduced to us as $U = mgy$. We usually set $U = 0$ on ground level and hence, for an object at height $y$, we have a potential energy equal to $U = mgy$.
I have adopted this convention when getting the potential for a system. For instance, a pendulum of mass $m$ attached to a massless string. I simply set $U = 0$ on the ground level. Hence, the height of the mass pendulum can be written as $y = l(1-\cos\theta)$.
When reading books by Marion and Thornton or Morin, they sometimes set the $U=0$ at the top of the system. For instance, consider a pulley with mass $m_1$ and $m_2$ attached at the left and right side of the string around it. They set $U=0$ at the center of the pulley and simply give the potential of the system as something like $U = -mgy_1 - mgy_2$ without any explanation.
They could have either simply set the coordinate system such that $+y$ is set to be downwards... but the potential should be invariant regardless of the coordinate system used, right?
The only reason I can think of for the negative sign is that near the top of the pulley, the potential should be greater than when it is far away from the pulley ($0 > -mgy_1$). Is this right? I have also read online that when you define $U = mgy$, then $+y$ must point away from the center of the earth. Could someone provide a good intuition about this?
TL;DR Having a hard time in getting the right sign for the potential when writing the lagrangian of the system.
 A: TL;DR By definition, the work done by a conservative force equals the negative of the change in potential energy
$$W = -\Delta U = U_1 - U_2 \tag 1$$
where $\Delta$ symbol always represents final value minus initial value. From this you can derive an expression for the gravitational potential energy $U_g$ for any coordinate system.


They could have either simply set the coordinate system such that +y is set to be downwards... but the potential should be invariant regardless of the coordinate system used, right?

The expression for the gravitational potential energy $U_g = mgy$ is only valid if positive $y$ direction points upwards (away from Earth's center). If you do it the other way around, the sign must also reverse in the expression for the gravitational potential energy.
The work done by the gravitational force on an object when positive $y$ direction points upwards, i.e. away from the Earth's center, is
$$W_g = \int_{y_1}^{y_2} -mg \hat{\jmath} \cdot dy \hat{\jmath} = \Bigl. -mgy \Bigr|_{y_1}^{y_2} = +mgy_1 - mgy_2 \qquad \text{(positive up)} \tag 2$$
and when positive $y$ direction points downwards (towards the Earth's center) the work is
$$W_g = \int_{y_1}^{y_2} +mg \hat{\jmath} \cdot dy \hat{\jmath} = \Bigl. +mgy \Bigr|_{y_1}^{y_2} = -mgy_1 + mgy_2 \qquad \text{(positive down)} \tag 3$$
By comparing Eqs. (2) and (3) with Eq. (1) we conclude that $U_g = +mgy$ when positive direction is up, and $U_g = -mgy$ when positive direction is down.

I have also read online that when you define $U=mgy$, then $+y$ must point away from the center of the earth. Could someone provide a good intuition about this?

There is no special reason why, it is just a convention which you are free to change as long as you follow it through the end. You can do it the other way around, just reverse the sign as already explained.

When reading books by Marion and Thornton or Morin, they sometimes set the $U=0$ at the top of the system.

This might be unusual but is not wrong. If positive $y$ direction points upwards in their coordinate system, then they will get negative values for gravitational potential energy of other parts of the system. You are free to arbitrarily choose the reference point for $y$ since change in gravitational potential energy is what matters and any offset naturally cancels in the subtraction.
A: This is because, when near earth, at the surface, when we define U=0, as we move some height(h) up, potential energy increases by amount $mgh$.
Similarly, when we go down, potential increases by amount $-mgh$.
So when dealing with Gravitational force, which is attractive in nature.
We define U=0 at infinity (You can define it 0 at any location as only change in potential energy matters), when we go some distance up, the potential energy increases. Say, from Earth we were at distance $R_1$, and we moved to distance $R_2$.
The change in potential energy is $-GM_1M_2(\frac{1}{R2} - \frac{1}{R1})$. Since, $R_2 > R_1$, $\Delta U$ is positive, as expected.
A: $U = mgy$ isn't a convention or an approximation, it's $false$. If you can change the amount of energy in the universe by defining a different origin, the laws of physics won't work reliably. I don't know why introductory physics classes persist in teaching it that way, it causes heaps of confusion.
If we use $\Delta U = -mg\Delta y$, we have a valid approximation, for appropriately signed $g, y$. Specifically, we can note that objects fall, so decreasing y must mean increasing kinetic energy; and energy is conserved, so increasing kinetic energy must correspond to a negative change in  potential energy. $-g$ should therefore be positive if negative changes in $y$ constitute decreasing height.
$g$ stands for acceleration due to gravity, which obviously points in the direction of negative changes in height, and should therefore be negative if decreasing height corresponds to decreasing $y$, so $-g$ is positive.
