There are a few steps to make sense of that procedure. 1. [Spectral Theorem][1] is a theorem that guarantees that there are solutions to the Time Independent Schroedinger Equation. 2. Those solutions will form a basis, and are also orthogonal and real. What happens here is that, even though the proof of the principle involves constructing a trial function as an expansion of the eigen-functions, which form a basis, the result is valid in general. There are no requirements for the trial function, but as any function, it could be expressed in terms of a basis, like a linear combination of the eigen-functions. So in reality, the trial function may be anything (respecting boundary conditions and so on.), and we can still be sure to be above the ground state energy. [1]: https://en.wikipedia.org/wiki/Spectral_theorem