Consider $$y'' + y = 0, \forall x \in (0,\pi)$$
with boundary conditions $y(0)=y(\pi) = 0$
The general solution is :
$$y(x) = a\cos(x) + b\sin(x), \forall x \in (0,\pi)$$
This equation (in a more general form at least) can be found in the process of trying to solve a pde by separation of variables(e.g. heat equation). My question is: given that the region where the ODE holds is the open interval $(0,\pi)$ why is it "legal" to apply the boundary conditions in the general solution?