Let $A$ be a unital C*-algebra.
As was already noted in the comments, we have $n(A)=1$ if and only if $A$ has a character.
Let $M_n=M_n(\mathbb{C})$.
It is easy to see that $n(M_n)\leq n$. Conversely, a linear subspace of $M_n$ of codimension less than $n$ contains an invertible matrix, as shown by Dieudonné, [1], see also [2]. Thus $n(M_n)=n$.
If $\pi\colon A\to B$ is a surjective ${}^*$-homomorphism onto another C*-algebra $B$, then $n(A)\leq n(B)$. Indeed, let $B_0$ be a subspace of $B$ of codimension $n(B)$ such that $B^{-1}\cap B_0=\emptyset$. Set $A_0:=\pi^{-1}(B_0)$. Then $A_0$ has codimension $n(B)$ in $A$ and $A^{-1}\cap A_0=\emptyset$. Therefore $n(A)\leq n(B)$.
Next, let $X$ be a compact, Hausdorff space and consider $A=C(X,M_n)=C(X)\otimes M_n$. We show $n(A)=n$.
First, for every $x\in X$, there is a surjective ${}^*$-homomorphism $\pi_x\colon A\to M_n$ given by evaluating at $x$. It follows $n(A)\leq n$. Let us show that the converse inequality also holds. So assume there exists a subspace $A_0$ of noninvertible functions of codimension $\leq n-1$. Then there are at most $n-1$ points in $X$ such that $\pi_x(A_0)\neq M_n$, say $x_1,\ldots,x_k$. For each $j\in 1,\ldots,k$, since $A_0$ has codimension $\leq n-1$, we have that $\pi_{x_j}(A_0)$ has codimension $\leq n-1$, and so $\pi_{x_j}(A_0)$ contains an invertible matrix. Since the set $\{x_1,\ldots,x_k\}$ is discrete in $X$, we can easily construct an invertible element in $A_0$, a contradiction.
One could now ask if $n(A)<\infty$ if and only if $A$ has a (nonzero) finite-dimensional representation (equivalently, a nonzero, finite-dimensional quotient C*-algebra).
[1] Dieudonné: Sur une généralisation du groupe orthogonal à quatre variables, Arch. Math. 1, 282-287 (1949)
[2] Fillmore, Laurie, Radjavi: On matrix spaces with zero determinant, Linear multilinear algebra 18, 255-266 (1985)