For a particle in a well, the energy eigenfunctions are in the form, $$\psi(x)=\sqrt\frac{2}{a}\sin\bigg(\frac{n\pi}{a}x\bigg)$$ And from Fourier theorem, which says that any function can be represented by a linear combination of sine functions. Therefore eigenfunction can span the Hilbert space.
In David J Griffiths, Introduction to Quantum Mechanics Second Edition, p. 131 Eqn. 3.75, he mentions that
The wave function $\Psi(x,t)$ is actually the coefficient in the expansion of $|\mathcal S\rangle$ in the basis of position eigenfunctions: $$\Psi(x,t) = \langle x|\mathcal S\rangle$$
where $|\mathcal S\rangle$ is the state vector. How can we be sure that the position operator has enough eigenbasis to span the whole Hilbert space.
For instance, say, that a operator $A$ is defined as, $$A=\begin{bmatrix} 1&1\\0&1\end{bmatrix}$$ has eigenvalue 1 and a eigenvector $\begin{bmatrix}1\\0\end{bmatrix}$ which is not enough to span the 2D space.
Similarly, how can we be sure that the eigenvectors of the the position operator can span the whole space? Also, is it a coincidence that the eigenbasis of the Hamiltonian are orthogonal to each other?