The following reference should be of interest :
Brewer, Montgomery, Rutter, Heinzer, Krull dimension of polynomial rings.
For example, they prove, see Corollary 2 p. 30, that any semi-hereditary ring (all finitely generated ideals are projective) satisfies the dimension formula above. This generalizes Seidenberg's result since a Prüfer ring is a semi-hereditary integral domain.
It might be interesting to study the class of rings $R$ satisfying the following condition : for every prime ideal $P$ of $R$ and every $n \geq 1$, we have $\textrm{height}(P[X_1,\ldots,X_n]) = \textrm{height}(P)$. This condition implies $\dim R[X_1,\ldots,X_n] = \dim R +n$ for every $n$ (this can be deduced from Thm 1 of this paper), but I don't know about the converse.
The authors also discuss the class of strong $S$-rings introduced by Kaplansky (see the paper for the definition). This class contains the Noetherian rings and the Prüfer rings, and is stable by localizations and quotients. Kaplansky proved that a strong $S$-ring $R$ satisfies $\mathrm{height}(P[X]) = \textrm{height}(P)$ for every prime ideal $P$ of $R$, and thus $\textrm{dim}(R[X])=\textrm{dim}(R)+1$. But a strong $S$-ring doesn't necessarily satisfy the dimension formula for every $n$. In the other direction, the authors give an example of a ring which satisfies the height formula $\textrm{height}(P[X_1,\ldots,X_n]) = \textrm{height}(P)$ for every prime ideal $P$, but which is not a strong $S$-ring.
Best Answer
There is a nice criterion that is usually applied in this situation.
A is flat over $R$ if the Krull dimension of the fiber ring $A_{\mathfrak{P}}/\mathfrak{P}$ for all prime ideals $\mathfrak{P} \subset R$ is $n-r$ (or the fiber is empty). In scheme theoretic language, the fibers either have the expected dimension (are complete intersections) or are empty. This is what is called a relative global complete intersection here https://stacks.math.columbia.edu/tag/00SK. Flatness follows from https://stacks.math.columbia.edu/tag/00SW.
This is a generalization of the criterion you cited when $r=1$. In that case the fibers of $Spec(R[x_1, \ldots, x_n]) \to Spec(R)$ are affine spaces over a field (so integral) and the condition ensures that the restriction of the polynomial $f$ to every fiber over some closed and open subset $U \subset Spec(R)$ is nonzero, so it must cut a closed subset of the fiber of dimension $n-1$ (or empty if it restricts to a constant). The idempotent comes from the fact that if $Spec(R)$ is not connected, then we can allow the preimage over the complement of this open and closed to be just isomorphic to the whole affine space $\mathbb{A}^n_{Spec(R) \setminus U}$, ($f$ is allowed to be identically $0$ on $Spec(R) \setminus U$).