This definition looks completely arbitrary, I fail to see why the class group or the ideal class group is worth studying.
I share the feeling. I will try to add another motivation I found reading [Koch 2000], which has been more satisfying for me, but leads to an early introduction of orders in the theory (which is not uncommon).
One of the first results proven on ANT is the following (cf. [Milne 2020, Proposition 2.4]):
Theorem. Given a number field $K/\mathbb Q$, a number $\alpha\in K$ is an algebraic integer of $K$ (ie., satisfies a polynomial in $\mathbb Z[x]$) if and only if there is a finitely generated $\mathbb Z$-submodule of $K$ that is invariant unde multiplication by $\alpha$.
Thus, we have a correspondence from the ring of integers of $K$ to the set of finitely generated $\mathbb Z$-submodules of $K$. Studying the ring of integers is studying all integer elements, so under this correspondence, we wish to study all such modules. Name this collection $\mathfrak M_K$.
We have a map $\mathcal O_K \to \mathfrak M_K$. Can we define a map that goes backwards? The thing is, given $\mathfrak m\in\mathfrak M_K$, we can't produce single algebraic integer, but a whole subring of $\mathcal O_K$ (this is the content of the proof of the theorem), which is also a finitely generated $\mathbb Z$-submodule of $K$, namely its ring of coefficients or order, $$\mathcal O_{\mathfrak m} := \{\alpha \in K \colon \alpha\mathfrak m \subseteq \mathfrak m\}.$$
So the set of orders $\mathfrak{O}_K := \mathfrak M_K \cap \{\text{subrings of $\mathcal O_K$}\}$ not only tracks the ring of integers of $K$—the maximal order of $K$—, but also a broader family of structures that might capture more arithmetic information of $K$.
Naturally we should investigate these orders. Some questions are: given $\mathcal O \in \mathfrak O_K$, what modules $\mathfrak m \in \mathfrak M_K$ map to $\mathcal O$? How many are there? At a first glance, infinitely.
To give a meaningful answer, note that if $\mathfrak m$ maps to $\mathcal O$, then also does $\alpha \mathfrak m$ for any $\alpha \in K^\times$, by the definition of order. In fact, this defines a equivalence relation in the set $\mathfrak M_{\mathcal O}$ of the modules that map to $\mathcal O$: declare $\mathfrak m \sim \mathfrak m'$ if there is $\alpha \in K^\times$ such that $\mathfrak m'= \alpha\mathfrak m$. Now the answer is actually interesting:
Theorem. Given a number field $K/\mathbb Q$, the set $\mathfrak M_{\mathcal O}/\sim$ is finite for any $\mathcal O \in \mathfrak O_K$.
In the particular case of $\mathcal O_K$ the maximal order, the ring of integers of $K$ (or more generally a Dedekind domain), the set $\mathfrak M_K$ of finitely generated $\mathcal O_K$-modules of $K$ is an abelian group, and the relation $\sim$ defines a (normal) subgroup, consisting of the principal fractional ideals, and the quotient is the class group.