As everyone knows, all functions of quantum computing are inverses of
each other. Hence, the 2 H gates cancel out.
Quantum gates all have inverses, but the inverse of a gate is not necessarily the same gate, though Hadamard gates, which are the ones being most considered here, are their own inverse. I'm not sure if by "2 H gates" you mean the two gates before the CNOT in the smaller diagram, which are on different qubits, or the two $H^{\otimes 2}$ gates flanking the CNOT in the larger diagram. In the former case, there's no cancellation since they are on different qubits. In the other case, they don't cancel because there is the CNOT between them and matrix multiplication is non-commutative: since $AB \neq BA$ is possible, you can't conclude $A^{-1}BA = A^{-1}AB = B$, and thus the two sets of Hadamards don't cancel out.
Now that we know that they don't just cancel out, you can derive that a CNOT with $H^{\otimes 2}$ flankings actually together make another CNOT with swapped control and target qubits. First, here is the conceptually simple but really tedious matrix multiplication of that:
$$\frac{1}{4}\begin{bmatrix}1 & 1 & 1 & 1 \\ 1 & -1 & 1 & -1 \\ 1 & 1 & -1 & -1 \\ 1 & -1 & -1 & 1 \end{bmatrix} \begin{bmatrix}1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0\end{bmatrix} \begin{bmatrix}1 & 1 & 1 & 1 \\ 1 & -1 & 1 & -1 \\ 1 & 1 & -1 & -1 \\ 1 & -1 & -1 & 1 \end{bmatrix} = \frac{1}{4}\begin{bmatrix}1 & 1 & 1 & 1 \\ 1 & -1 & 1 & -1 \\ 1 & 1 & -1 & -1 \\ 1 & -1 & -1 & 1 \end{bmatrix} \begin{bmatrix}1 & 1 & 1 & 1 \\ 1 & -1 & 1 & -1 \\ 1 & -1 & -1 & 1 \\ 1 & 1 & -1 & -1\end{bmatrix} = \begin{bmatrix}1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0\end{bmatrix}$$.
With $a\left|00\right> + b\left|01\right> + c\left|10\right> + d\left|11\right> = \begin{bmatrix} a \\ b \\ c \\ d \end{bmatrix}$, we see the original in the flank swaps the probability amplitudes of $\left|10\right>$ and $\left|11\right>$ (left qubit is control), while the new one swaps the amplitudes of $\left|01\right>$ and $\left|11\right>$ (right qubit is control).
A harder but interesting and less tedious way to recognize this is through the symmetry of the controlled-$Z$ gate, as described in page 5 of https://arxiv.org/pdf/1110.2998.pdf. A controlled-$Z$ gate's control and target qubits are indistinguishable since the only probability amplitude in computational basis that changes is the sign flip of the probability amplitude of $\left|11\right>$. However, if one of the qubits in the controlled-$Z$ has Hadamards flanking it, they together are a CNOT with the Hadamard-flanked qubit being the target. Add the $H^{\otimes 2}$ on both sides to this CNOT and you have the "control" qubit of the controlled-$Z$ gate with a Hadamard behind and in front of it, and the "target" qubit with two on each side. The two Hadamards on each side for that qubit cancel out since there is nothing between them, so it ends up with a controlled-$Z$ with Hadamards behind and in front of what we previously noted as the control, but, since a controlled-$Z$ doesn't distinguish control and target, that is instead the target of a CNOT due to the Hadamards, and we have the switch.