$$\underline{\text{A General Discussion About Potential Energy}}$$
My answer is simply going to expand on <PERSON>'s answer. Hopefully, observing the argument from multiple viewpoints should help in understanding.
Let's say force $\mathbf{F}$ is acting on a point mass $m$ that follows the trajectory $C$ from point $1$ to point $2$ in three dimensional space (You can think of point $1$ as labelled by ${x_1,y_1,z_1}$ : $\mathbf{r}1=x_1 \hat{x} + y_1 \hat{y} +z_1\hat{z}$). In general, we have the following : $$G(\mathbf{r}_1,\mathbf{r}_2,C)\stackrel{\text{Definition}}{:=}\int{1\; :\; C}^2 \mathbf{F} \cdot d\mathbf{r}=W_{1 \to 2 \; : \; C} \tag{1}$$
From $(1)$ you observe that the integral on the right hand side depends in general on $\mathbf{r}1$, $\mathbf{r}_2$, and the trajectory $C$ connecting $1$ and $2$. However, there exists a special class of forces (called the conservative forces) for which the integral on the RHS of $(1)$ doesn't depend on the trajectory $C$ but only on the initial and final end points of the trajectory. 766
If $\mathbf{F}$ is a conservative force, then we have the following : $$G(\mathbf{r}_1, \mathbf{r}_2)=\int{1 \;:\; \text{any $C$ connecting $1$ and $2$}}^2 \mathbf{F} \cdot d\mathbf{r} \tag{2}$$
If $\mathbf{F}$ is conservative, we can show mathematically that there exists a function $U$ (called the potential energy) that obeys the following : $$U(\mathbf{r}1) - U(\mathbf{r}_2) = \int{1 \;:\; \text{any $C$ connecting $1$ and $2$}}^2 \mathbf{F} \cdot d\mathbf{r} \tag{3}$$
However, there is not a unique $U$ but instead a class of such $U$ each of which differ from each other by a constant. You can see this from $(3)$ : Given $U(\mathbf{r})$ satisfies $(3)$, we can see that $U'(\mathbf{r})= U(\mathbf{r})+a$ also satisfies $(3)$ since $a$ just gets cancelled by subtraction.
$$\underline{\text{Detour}}$$ You may wonder how $G$, which seems like an arbitrary function of 6 variables in $(2)$, can be expressed as the difference of function $U$ of 3 variables in $(3)$. For example,
$$\text{Couldn't $G$ be } G(x_1,y_1,z_1,x_2,y_2,z_2) = k(x_1x_2^2+y_1y_2^2+z_1z_2^2)\text{?}\tag{4}$$
The answer is no. To understand this, you need to realize that $G$ is not as completely arbitrary as one might think. 610