I am not able to finalize the proof of this statement, and it seems something is always omitted in textbooks. Here there is what I got so far. (I'm trying to find the proof for a classical real-valued function, not for extended real-valued functions, I hope this is not an obstacle).
A function $f: \text{dom}f \subseteq X \to \mathbb{R} $ ( $X$ is a topological space) is said to be closed if its epigraph is closed: $$\text{epi}f = \{(x,y) \in \text{dom}f \times \mathbb{R}: y \ge f(x)\} = \{(x,y) \in \text{dom}f \times \mathbb{R}: f(x) \le y \} = \{(x,y) \in \text{dom}f \times \mathbb{R}: x \in S_yf\}$$ where $ S_cf = \{x \in \text{dom}f : f(x) \le c\}$ is the $c$ sublevel set of $f$.
For a certain $y\in\mathbb{R}$, then $(x,y) \in \text{epi}f \Leftrightarrow x \in S_yf $ so $\text{epi}f$ is closed iff $S_yf $ is closed.
Now, everywhere it is said that a necessary and sufficient condition for a function to be closed, is that lower semi-continuity holds for each points in the domain:
$$\forall x_0 \in \text{dom}f, \forall \epsilon >0, \exists \delta > 0: f(x)\ge f(x_0) - \epsilon, \forall x \in B_\delta(x_0)$$ where $B_\delta(x_0)$ is the open ball centered in $x_0$ with radius $\delta$.
I'm already stuck with the sufficiency part.
Let's consider a point $\bar x \in \partial S_yf $, then from the definition of boundary of $S_yf$: $$\exists R>0: f(x) \le y, \forall x \in S_yf \cap B_R(\bar x) \setminus \{\bar x\}$$ where $S_yf \cap B_R(\bar x) \setminus \{\bar x\}$ is non empty.
If $\bar x \in \text{dom}f$, using the lower semicontinuity of $f$ in $\bar x$: $$\forall \epsilon >0, \exists \delta > 0: f(\bar x)\le f(x) + \epsilon, \forall x \in B_\delta(\bar x)$$
Since $f(x) \le y, \forall x \in B_R(\bar x) \cap S_yf \Longrightarrow f(x) + \epsilon \le y + \epsilon , \forall x \in S_yf \cap B_\delta(\bar x) \cap B_R(\bar x) \setminus \{\bar x\} $
where $ S_yf \cap B_\delta(\bar x) \cap B_R(\bar x) \setminus \{\bar x\} $ is again non empty.
Then $f(\bar x)\le f(x) + \epsilon \le c + \epsilon > 0, \forall \epsilon$ therefore, necessarily $f(\bar x)\le c \Rightarrow \bar x \in S_yf$.
If instead the point does not belong to the domain: $\bar x \notin \text{dom}f$, and, of course, $\bar x \notin S_yf $, so one must prove that this point cannot exist. The only thing I can prove is that, the function cannot have limit $+\infty$ in $\bar x$.
Again, $\exists R>0: f(x) \le y, \forall x \in S_yf \cap B_R(\bar x) \setminus \{\bar x\}$.
Let us consider any sequence $x_k \in \text{dom}f$ such that $x_k \in S_yf \cap B_R(\bar x) \setminus \{\bar x\}, \forall k \ge k_0$ such that: $$\lim_{k\to \infty} x_k = \bar x$$ then, since $f(x_k)\le y, \forall k \ge k_0$, this limit, if existing, can be $y$ at most.
Apparently I'm struggling to prove something that is not even true. As these slides(pages 5-7) from a MIT course state, the equivalence holds for functions having all $\mathbb{R}^n$ as their domain (or, in general, all $X$ topological space) and also:
"If $f$ is lower semicontinuous at all $x \in \text{dom}f$, it is not necessarily closed".
I am stil a bit confused by the last paragraph in "Formal definition" of semicontinuity Wikipedia page
EDIT:
I said "from definition of boundary", meaning simply I can always find some points in any neighborhood of a boundary point that belong to the set, so I used the intersection between a ball around a boundary point and the set itself, claiming that such a set is non empty (thanks to the definition of boundary). Only now I figure out that this statement is not so clear to read.
As regards the structure of the set $X = \mathrm{dom} f$, I don't understand which properties have to be satisfied in order to consider it a topological space (maybe my topology background is not so thick, I'm sorry, I'm just attending a Convex analysis and optimization master course). The proof of the first implication is clear enough for me, whereas in the second one ($2 \Rightarrow 1$) I don't get why the set $\{(x,y)\colon x\in X\}\subset X\times\Bbb R$ should be closed for each $y$: if $X$ is open how can this set be closed. Moreover the set $\{(x,y)\colon x\in X,f(x)\le y\}$ seems to me the epigraph itself. Regarding the next statement about the projection of this set over the set $X$ I think I'm missing the property that lets us infer the closedness after the projection.
As you pointed out, I guess the key point lies in the statement "$f$ is closed in $X$", that I think it is supposed to mean that even if $X$ is open it doesn't matter because the property must hold in any closed set inside it, but I am not sure to get this point. Even if I have already enough problems in properly understanding your explaination (sorry about that), I would like to make a very naive example which maybe could clarify better my not so clever perplexity. Let us consider the function $f\colon B_{R}(0) \subset \Bbb R^{2} \to \Bbb R, f(x) = \| x \| ^2$. This function is lower semicontinuous (actually even continuous over the open ball $B_{R}(0)$) but it is not closed, because for instance any sublevel set $S_c$ with $c \ge R^2$ is an open set.