One way of thinking about why the definition of equal cardinality in the infinite case is sensible is as follows.
First we think about cardinality in the finite case. You observe in your question that if you have one set $A$ strictly contained in another set $B$ (i.e. every element of $A$ is an element of $B$, but there are some of elements of $B$ that are not in $A$) then it would be nice to say that the size, or cardinality, of $B$ is larger than that of $A$, written $|B|>|A|$. This is a resonable definition to make, but it doesn't tell us much about what happens when one set is not contained in the other.
For example, let's take $A=\{0,1,2\}$ and $B=\{3,4,5,6\}$, so we have neither that $A$ is strictly contained in $B$, nor that $B$ is strictly contained in $A$. But we'd still like to give some meaning to our intuition that $B$ is larger. We could do this by counting elements, but we want to apply this reasoning to infinite sets later, where counting doesn't work quite so nicely, so we'll avoid that if possible. One think we could notice is that the function $A\to B$ defined by $0\mapsto 3$, $1\mapsto 4$ and $2\mapsto 5$, i.e. $x\mapsto x+3$, is injective, meaning that each element of $A$ is mapped to a different element of $B$. The existence of such a function turns out to be a good definition for $|A|\leq|B|$, as if $A$ had more elements than $B$ there couldn't be such a function. As we observe that there is no injective function $B\to A$, we have that $|B|\not\leq|A|$, so we should write $|A|<|B|$, which fits with our intuition.
As this definition doesn't depend on counting, it's a fairly natural definition to use in the case of infinite sets. The inclusion map ($x\mapsto x)$ from the integers to the rationals is clearly injective, so we find that $|\mathbb{Z}|\leq|\mathbb{Q}|$. However there are also various injections from $\mathbb{Q}\to\mathbb{Z}$, my favourite being that you should write each rational number as $\pm\frac{a}{b}$, with $a$ and $b$ positive and coprime, and then send that rational to the integer $\pm2^a3^b$ (the sign of the rational and the integer agree) - this is then injective by uniqueness of prime factorisation. So exactly as the integers sit inside $\mathbb{Q}$, there is a map which makes the rationals sit inside $\mathbb{Z}$ as well, and so it makes sense to say that $|\mathbb{Z}|=|\mathbb{Q}|$, even though $\mathbb{Z}$ is strictly contained in $\mathbb{Q}$.
Note also that while the inclusion is an injection $\mathbb{Z}\to\mathbb{R}$, there does not an exist an injection $\mathbb{R}\to\mathbb{Z}$, so $|\mathbb{Z}|<|\mathbb{R}|$.
Note: I've talked about two sets having an injection between them each way because this is a neater generalization of the notion of inclusion that you were talking about in the question, but it is equivalent to the existence of a bijection by the Cantor–Bernstein–Schroeder theorem.