Loss: $$L_1(\hat y,y)=|\hat y-y|$$
Suppose that $$\hat y=y+\varepsilon,$$
where the probability density of error $\varepsilon$ is $f(\varepsilon)$.
Now, we can solve the problem $$\min_{\hat y} E[L_1(\hat y,y)]$$ using first order condition (FOC):
$$\partial/\partial\hat y E[L_1(\hat y,y)]=0$$
$$\partial/\partial\hat y E[L_1(\hat y,y)]=
E[\partial/\partial\hat y |\hat y-y|]=
\int_{-\infty}^{\hat y-y}f(e)de-\int_{\hat y-y}^{\infty}f(e)de
=F(\hat y-y)-(1-F(\hat y-y))=2F(\hat y-y)-1=0$$
Where $F(.)$ is the cumulative distribution function.
Also I substituted $\hat y-y$ with $e$ in the integrals.
You can see that the FOC is satisfied when $F(\hat y-y)=1/2$, i.e. when the $\hat y$ is at the median of the distribution.
You can do the same for $L_2$ to show that it requires the mean.
Loss: $$L_2(\hat y,y)=(\hat y-y)^2$$
Suppose that $$\hat y=y+\varepsilon,$$
where the probability density of error $\varepsilon$ is $f(\varepsilon)$.
Now, we can solve the problem $$\min_{\hat y} E[L_2(\hat y,y)]$$ using first order condition (FOC):
$$\partial/\partial\hat y E[L_2(\hat y,y)]=0$$
$$\partial/\partial\hat y E[L_2(\hat y,y)]=
E[\partial/\partial\hat y (\hat y-y)^2]=
E[2 (\hat y-y)]=
2 (\hat y-E[y])]=0$$
You can see that the FOC is satisfied when $\hat y=E[y]$, i.e. when the $\hat y$ is at the mean of the distribution.