In the commutative case $A=C(K)$, this is equivalent to asking for which compact Hausdorff spaces there are no continuous surjections $K\to[0,1]$, since the spectrum of $f\in C(K)$ is its image. A compact Hausdorff space $K$ has this property iff $K$ is scattered: that is, iff every nonempty subset of $K$ has an isolated point.
Indeed, suppose $K$ is not scattered. Then $K$ contains a nonempty subset $P\subseteq K$ with no isolated points, which we may assume to be closed (take its closure). If $P$ has a nontrivial connected subset $Q$, then any function in $C(Q)$ has connected image, and thus any nonconstant function on $Q$ gives a continuous surjection $Q\to[0,1]$. Otherwise, $P$ is totally disconnected, and so since $P$ is perfect it surjects onto the Cantor set. Since there is a continuous surjection from the Cantor set to $[0,1]$, there is a continuous surjection $P\to [0,1]$.
In either case, we get a continuous surjection from a closed subspace of $K$ to $[0,1]$. This function then extends to a continuous surjection $K\to[0,1]$.
Conversely, suppose there exists a continuous surjection $f:K\to[0,1]$. Note that if $\mathcal{C}$ is a chain of closed subsets of $K$ on which $f$ is surjective, then $f$ is also surjective on $\bigcap\mathcal{C}$, since for each $x\in[0,1]$ the sets $S\cap f^{-1}(\{x\})$ for $S\in\mathcal{C}$ are closed and have the finite intersection property. So by Zorn's lemma, there exists a minimal closed subset $P\subset K$ on which $f$ is surjective. This subset $P$ cannot have an isolated point $x$, since then $P\setminus\{x\}$ would be closed but $f$ would be surjective on $P\setminus\{x\}$ since its image must be closed in $[0,1]$ and contain all but at most one point of $[0,1]$. Thus $K$ is not scattered.
Some examples of compact Hausdorff scattered spaces include all compact Hausdorff spaces of cardinality $<2^{\aleph_0}$, one-point compactifications of discrete spaces, and successor ordinals. A closed subset of $\mathbb{C}$ is scattered iff it is countable, and it follows easily that if $K$ is compact Hausdorff and scattered, then actually every element of $C(K)$ has countable spectrum.
Finally, to address your last question, if $K$ is infinite, compact, and extremally disconnected, then $K$ is not scattered. Indeed, in that case $K$ is the Stone space of an infinite complete Boolean algebra $B$. Since $B$ is infinite, it contains a countably infinite set of disjoint nonzero elements $\{b_0,b_1,b_2,\dots\}$. We may assume the join of all of these elements is $1$ (if not, add the complement of the join as one more element in the set). There is then an embedding of Boolean algebras $\mathcal{P}(\mathbb{N})\to B$ sending $S\subseteq\mathbb{N}$ to $\bigvee_{n\in S}b_n$. This dually gives a continuous surjection from $K$ to the Stone space $\beta\mathbb{N}$ of $\mathcal{P}(\mathbb{N})$. There exists a continuous surjection $\beta\mathbb{N}\to[0,1]$ (map $\mathbb{N}$ to a countable dense subset of $[0,1]$), and thus there exists a continuous surjection $K\to[0,1]$.
I don't really know anything about the noncommutative case, but apparently there is a notion of a "scattered $C^*$-algebra" which there is a lot of literature on and which I would guess is equivalent to your condition.