if your original pde was the heat equation with zero temperature at finite ends then you should have.
$$ \begin{align}\begin{cases} \frac{\partial u}{\partial t} = k\frac{\partial^{2} u}{\partial x^{2}} & 0 < x < L, t > 0 \\ u(0,t) =0 \\ u(L,t) = 0 \\ u(x,0) = f(x) \end{cases} \end{align} \tag{1}$$
which would give you
$$ u(x,t) = B \sin(\sqrt{\lambda}x) e^{-k \lambda t} \tag{2} $$
this becomes
$$ u(x,t) = \sum_{n=1}^{\infty}B_{n} \sin(\sqrt{\lambda}x) e^{-k \lambda t} \tag{3} $$
to solve for the coefficients, we note that
$$\int_{0}^{L} \sin(\frac{n \pi x}{L})\sin(\frac{m \pi x}{L}) dx = \begin{align}\begin{cases} 0 & m \neq n \\ \frac{L}{2} & m =n \end{cases} \end{align} \tag{4} $$
then we do the following. This is called Fouriers Trick. We multiply $f(x)$ by $\sin(\frac{m \pi x}{L})$ and
$$ f(x) \sin(\frac{m \pi x}{L}) = \sum_{n=1}^{\infty} B_{n} \sin(\frac{n \pi x}{L}) \sin(\frac{m \pi x}{L}) \tag{5} $$
The question is about here
When you go from step $5$ on. You take the integral from $\int_{0}^{L}$ of both sides.
$$ \int_{0}^{L} f(x) \sin(\frac{m \pi x}{L}) dx = \int_{0}^{L} \sum_{n=1}^{\infty} B_{n} \sin(\frac{n \pi x}{L})\sin(\frac{m \pi x}{L}) dx \tag{6}$$
there is a theorem on this page
Theorem: if $ \{ f_{n} \}_{n} $ is a positive sequence of integrable functions and $f = \sum_{n} f_{n} $ then
$$\int f = \sum_{n} \int f_{n} \tag{7} $$
this comes from the monotone convergence theorem.
$$ \int_{0}^{L} f(x) \sin(\frac{m \pi x}{L}) dx = \sum_{n=1}^{\infty} B_{n} \int_{0}^{L} \sin(\frac{n \pi x}{L})\sin(\frac{m \pi x}{L}) dx \tag{8}$$
now when $ m \neq n$ that is $0$ so we have
$$ \int_{0}^{L} f(x) \sin(\frac{m \pi x}{L}) dx = B_{m} \sum_{n=1}^{\infty} \int_{0}^{L} \sin^{2}(\frac{m\pi x}{L}) dx \tag{9}$$
which then yields
$$ B_{m} = \frac{\int_{0}^{L} f(x) \sin(\frac{m \pi x}{L}) dx}{ \int_{0}^{L} \sin^{2}(\frac{m\pi x}{L}) dx} = \frac{2}{L} \int_{0}^{L} f(x) \sin(\frac{m \pi x}{L}) dx \tag{10}$$