First, the minimization problem $\min_{f \in P_n(I)} \int_0^1 \lvert \sum_{i=0}^n f_ix^i-g(x) \rvert^2 dx$ is a function of the coefficients $f_i$ and not of $x$.
Second, $\int_0^1 (f(x)-g(x))^2 dx = \int_0^1 f^{2}(x)+g^{2}(x) - 2f(x)g(x) dx$. But since the $g^2(x)$ term isn't a function of $f_i$ we can ignore this term in the optimization, i.e., $\min_{f \in P_n(I)} \int_0^1 \lvert f(x)-g(x) \rvert^2 dx = \min_{f \in P_n(I)} \int_0^1 f^2(x) - 2f(x)g(x) dx$. The integral of $f^2(x)$ is easy to compute since it is the integral of a polynomial squared. Using integration by parts the integral of $f(x)g(x)$ equals,
\begin{align}
\int_0^1 f(x)g(x) dx &= \left[f(x)g^{(-1)}(x)\right]^{1}_{0} - \int^{1}_{0} f^{(1)}(x)g^{(-1)}(x) dx
\end{align}
where $h^{(i)}$ is the $i$-th derivative of $h$ and $h^{(-i)}$ is the $i$-th antiderivative of $h$. Note that since $g$ is continuous we know that the integral exists How to prove that continuous functions are Riemann-integrable? and we know that polynomials are differentiable and integrable. Additionally, the integral of a continuous function is also continuous Is an integral always continuous?. We can repeat this process again on remaining integral term i.e,
\begin{align}
\int_0^1 f(x)g(x) dx &= \left[f(x)g^{(-1)}(x)\right]^{1}_{0} - \int^{1}_{0} f^{(1)}(x)g^{(-1)}(x) dx \\
&= \left[f(x)g^{(-1)}(x)\right]^{1}_{0} - \left[f^{(1)}(x)g^{(-2)}(x)\right]^{1}_{0} + \int^{1}_{0} f^{(2)}(x)g^{(-2)}(x) dx \\
&= \sum_{i=0}^{n} (-1)^i\left[f^{(i)}(x)g^{(-i-1))}(x)\right]^{1}_{0}
\end{align}
The process ends after the $n$-th derivative of $f(x)$ since $f^{(n+1)}(x) = 0$.
Third, the integral of $f^2(x)$ will be a quadratic in $f_i$ and the integral of the $f(x)g(x)$ term will be linear in $f_i$. Therefore, after computing the integral out you can write the problem as a quadratic minimization problem over $f_i$.