There are a few steps to make sense of that procedure.
- Spectral Theorem is a theorem that guarantees that there are solutions to the Time Independent Schroedinger Equation.
- Those solutions will form a basis, and are also orthogonal and real, since H is required to be Hermitian.
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.