When does the prime spectrum deformation retract into the maximal spectrum? For which rings is the maximal spectrum a deformation retract of the prime spectrum?
For instance, a comment to the answer to this MO question mentions it's the case if we take the ring to be the ring of continuous (real) functions over a compact connected metric space. What are some other examples and more general conditions?
 A: Added: Sorry, I wrote this answer rather late at night and completely ignored the word "deformation" in the question.  This answers the version of the question with "retract" instead of "deformation retract".  The two things are not in general the same (e.g. every topological space retracts onto each of its points).  Still this answer gives necessary conditions for a deformation retraction, at least, and I hope it will be of some use.
This class of rings is called Gelfand rings.  Proposition 1.3 of this 2006 paper of W.W. McGovern gives several equivalent conditions.  I will reproduce the first four:

Proposition: For a commutative ring $R$, the following are equivalent:
  (i) Every prime ideal of $R$ is contained in exactly one maximal ideal.
  (ii) $\operatorname{Spec} R$ is a normal (not necessarily Hausdorff) topological space.
  (iii) $\operatorname{MaxSpec} R$ is a retract of $\operatorname{Spec} R$.
  (iv)  For all $x \in R$, there are $r,s \in R$ such that $(1+rx)(1+s(1-x)) = 0$.

Much of the proof refers you back to a 1971 paper of De Marco and Orsatti.
Here is a very useful related paper of Banaschewski.  In particular Banaschewski directly verifies the somewhat weird-looking condition (iv) for the class $C(X)$ of rings of continuous, real-valued functions on a compact Hausdorff space.  This is (a moderate generalization of) the class of rings you mention, and indeed the nomenclature here is an allusion to the Gelfand duality between compact Hausdorff spaces $X$ and $C(X)$ (namely that the canonical map $X \rightarrow \operatorname{MaxSpec} C(X), \ x \mapsto \mathfrak{m}_x = \{f \in C(X) \mid f(x) = 0\}$ is a homeomorphism).  Note that condition (iv) also makes clear that Gelfand rings are finitely axiomatizable in the first order language of rings and is thus closed under ultraproducts and elementary equivalence.
Further Added: Following Eric Wofsey, I believe that in this case we get a deformation retraction whenever we have a retraction.  Namely, if $R$ is a Gelfand ring and $r: \operatorname{Spec} R \rightarrow \operatorname{MaxSpec} R$ sends each prime ideal to the unique maximal ideal containing it (by the way, this is the unique retraction), then $H: \operatorname{Spec} R \times [0,1] \rightarrow \operatorname{Spec} R$ given by $H(\mathfrak{p},t) = \mathfrak{p}$ for all $t \in [0,1)$ and $H(\mathfrak{p},1) = r(\mathfrak{p})$ is continuous!  In fact for any closed subset $Z \subset \operatorname{Spec} R$, we have $H^{-1}(Z) =$ 
$$Z \times [0,1) \cup r^{-1}(Z \cap \operatorname{MaxSpec} R) \times \{1\} = Z \times [0,1] \cup r^{-1}(Z \cap \operatorname{MaxSpec} R) \times \{1\},$$
which is closed.   So -- quite fortuitously -- it looks like my original answer is correct.  
