Is Hamiltonian a scalar or tensor in Quantum Mechanics? According to Wikipeida, a scalar operator is invariant under rotations, and the Hamiltonian satisfies this definition. But at the same time, a Hamiltonian can be written as a matrix, which means it is a rank-2 tensor. Does it mean that a "scalar operator" may also be a tensor?
 A: The words "scalar", "tensor" and so on make sense in the context of a vector space with a given set of basis transformations. Physical quantities usually belong to many vector spaces at once, although we don't always make this explicit, only focusing on one of them at a time.
Here, we have (at least) three vector spaces at play: a Hilbert space $\mathcal{H}$, spacetime $\mathbb{R}^4$, and, given an observer, a subspace isomorphic to $\mathbb{R}^3$ representing space for that observer. Now, the Hamiltonian $H$ is first of all a linear operator $\mathcal{H} \to \mathcal{H}$, which makes it a (1,1) tensor. That is, given a basis $|n\rangle$ the Hamiltonian has components $H_{mn}$ (though we don't usually write it like this), with two indices.
Under rotations of the coordinates we use in 3D space, operators are changed as $A \mapsto U^\dagger A U$, with $U$ a unitary operator representing the rotation. And it so happens that $H$ doesn't change: $U^\dagger H U = H$. We say that $H$ is a scalar with respect to rotations. Some operators, like the components of momentum $P_i$, do change and mix among themselves, so it makes sense to pack them together as $(P_x, P_y, P_z)$ and say that they transform as a vector. And if we do Lorentz transformations, we find that $H$ does change, mixing with the $P_i$, so we pack them all together in a four-vector $(H, P_x, P_y, P_z)$, whose first component doesn't change if we only do rotations.
The TL;DR is that it depends on what vector space you're looking at, and what basis changes on that vector space. As another example, consider the wavefunction for a spin-1/2 particle, $\psi = (\psi_1, \psi_2)^T$. It has two components, each of which is an element of $\mathcal{H} = L^2(\mathbb{R}^3)$. So, is it a spinor or a state-vector? How does it transform under rotations: with the 2x2 spinor matrix, or with the operator $U$? The answer, obviously, is both. Or look at this answer of mine, where I discuss this same issue but regarding the adjoint of a vector.
