As the Wikipedia page notes, there are two ways to approach cardinality. One, which is what you are getting at here, is to construct the cardinal numbers and have a procedure that assigns each set $S$ a unique cardinal $Card(S)$. This construction is somewhat involved and is mostly the domain of set theorists and the like. Most ordinary mathematicians think of cardinality through the relations "$A$ has the same cardinality as $B$" denoted by $|A| = |B|$ and "$A$ has cardinality less than or equal to $B$", denoted by $|A| \leq |B|$.
We define $|A| = |B|$ as $\exists \phi:A \to B, \phi$ is a bijection. And we define $|A| \leq |B|$ by $\exists \phi: A \to B, \phi$ is an injection.
Then the Schroder-Bernstein theorem gives that $|A| \leq |B|$ and $|B| \leq |A| \implies |A| = |B|$.
Now if we just consider finite sets, we can alternatively define a "function" (note it won't be a true set function, since there is no set of all finite sets) $Card(S)$ that assigns a finite set $S$ a unique natural number that is its number of elements. We then can note that $Card(A) = Card(B) \iff |A| = |B|$ and $Card(A) \leq Card(B) \iff |A| \leq |B|$, so these two approaches are the same for finite sets.
Edit: Defining the $Card$ "function" for finite sets. Since $Card$ cannot be a set function as noted above, we are really looking for a predicate $\Phi(A,n)$ s.t. $A$ is finite implies $\exists! n \in \mathbb{N}, \Phi(A,n)$.
Denote $set(n) = \{0,...,n-1\}$. Define $\Phi(A,n) \iff n \in \mathbb{N} \land \exists \phi : A \to set(n), \phi$ is a bijection.
Then to show $\Phi$ has the properties we want, we note that uniqueness comes directly from the nonexistence of bijections between $set(n)$ and $set(m)$ for $n \neq m$ and since $A$ is finite can be defined to mean $\exists n \in \mathbb{N} \exists \phi : A \to set(n), \phi$ is a bijection, we get existence of some $n$ s.t. $\Phi(A,n)$ provided $A$ is finite.
Thus $\Phi$ defines a function, since to each finite $A$, we get a unique $n \in \mathbb{N}$.