As a rule of thumb, every quantum mechanical state is described as a vector in Hilbert space—you seem to understand this. But the most important thing to understand here, is that Hilbert spaces are extremely flexible. Loosely speaking, every vector space with a well-defined inner product is a Hilbert space, provided that the inner product of a vector with itself is always well-defined. If that sentence doesn’t make sense to you, please tell and I’ll add some context. Knowing about abstract vector spaces beyond the Euclidean ones is extremely useful!
Now onto the misconception in your question. You write that we can define the Hamiltonian operator as $\frac{-i\hbar}{2m} \frac{\partial^2}{\partial x^2} + V(x)$ (don’t forget the mass factor!), but this is not completely true. The Hamiltonian operator is the operator that has all the eigenstates of energy. Again, if you’re not exactly sure what eigenstates mean in Quantum mechanics, don’t hesitate to ask.
So if we have a system in some eigenstate of the Hamiltonian operator $\vert 1 \rangle$, we can be assured that any measurement of energy returns the value $E$ such that $\bar{H} \vert 1 \rangle = E\vert 1 \rangle$.
Because we want to do calculations with the Hamiltonian, and discover these energy eigenstates, we give the Hamiltonian a representation: we write it down into a form that we can use along with our state vectors. One of such representations is $\frac{-i\hbar}{2m} \frac{\partial^2}{\partial x^2} + V(x)$, but it is not the only one. Which representation you use depends fully on which problem you’re facing.
To further illustrate this. I’ll now introduce two quantum mechanical problems, requiring very different Hilbert spaces, along with very different Hamiltonian operators.
First of all, consider the situation in which we face a quantum mechanical system with three energy levels. We are interested in the system’s energy. We can then label these three energy states by their kets: $\vert 1 \rangle$, $\vert 2 \rangle$ and $\vert 3 \rangle$. In this case, a representation of the vectors and operators in $\mathbb{R}^3$ is very useful. Operators on such vectors are 3x3 matrices. I’m on my phone now, so I can’t write out the matrices and column vectors, but I’ll describe them. The ith energy state can be represented by the column vector whose ith entry is 1, with all other entries 0. The Hamiltonian is then not represented by $\frac{-i\hbar}{2m} \frac{\partial^2}{\partial x^2} + V(x)$, but by a matrix with the energy values on the diagonal and with zeroes elsewhere.
Second of all, consider the infinite one-dimensional potential well. We want to know where the particle is likely to be. Since we’re interested in the particle’s position, we will not describe the system’s state as a linear combination of energy eigenstates as before. Instead, we will elect to represent the system’s state as a wave function—quadratically integrable functions form a Hilbert space too! (If you don’t understand the last bit, tell me and I’ll elaborate) Formally, the wavefunction representation is the position basis representation while the previous example is the energy basis representation.
Now whenever we represent the system’s state as a wavefunction, we need to change the representation of our Hamiltonian accordingly. In the position basis, the Hamiltonian’s representation is $\frac{-i\hbar}{2m} \frac{\partial^2}{\partial x^2} + V(x)$! Understanding why the Hamiltonian’s representation looks like this is a little harder than the first example. Fundamentally, the Hamiltonian for a particle is exactly equal to $\frac{\hat{p}^2}{2m} + V(x)$ and the momentum operator is chosen accordingly. But that goes beyond the scope of this answer.