One of the first proofs in group theory is to show that in a finite $G$, the order of the element $g$ is the same as the order of the subgroup $\langle g \rangle$. Let the order of $g$ equal $m$. Via the division algorithm on $\mathbb Z$ and the definition of the cyclic group, it can be shown that:
$$\langle g \rangle = \{ 1, g, g^2 ... g^{m-1} \}$$
But we also need to prove that each element on the right-hand side is unique before concluding that the order of $\langle g \rangle$ is $m$. In the context of the proof, it makes sense to check that each element is unique. However, in general, when we say that the two sets are equal, we also mean that they have the same number of elements.
Thus, when do you need to check separately that the two sets have the same number of elements, and when can you accept directly that $A = B \rightarrow |A| = |B|$?
This is just a specific instance of the fact that if $A=B$ then $f(A)=f(B)$, no matter what $A$ and $B$ and $f$ are. If $A$ and $B$ are the same set, their size is certainly equal.
I think, in the context of the proof you're looking at, what may be confusing is that even if you can easily prove that $$\langle g\rangle = \{1,g,g^2,\ldots,g^{m-1}\}$$ you don't actually know what the size of either of those sets is. So, to establish that, you show that all the elements of the left hand are distinct, and hence that set has $m$ elements. Consequently $\langle g\rangle$, which is equal, also has $m$ elements.
This is to say, we could equally validly write: $$\langle g\rangle = \{1,g,g^2,\ldots,g^{m-1},g^m\}$$ which makes it look like $\langle g\rangle$ has $m+1$ elements - since we listed $m+1$ terms on the left. However, the set on the right only contains $m$ elements as $1=g^m$ is listed twice. So, in order to use such a representation to state how large $\langle g\rangle$ is, we need to assure ourselves of the size of the set on the right. From there, it immediately follows that $\langle g \rangle$ has equally many elements.