Without further hypotheses on $S$, there are counterexamples.  For instance, begin with $\widetilde{S}$ equal to the affine line $\mathbb{A}^1_k = \text{Spec} \ k[s]$.  Inside of the affine space $\mathbb{A}^2_S = \text{Spec}\ k[s,t,u]$, consider the closed subscheme $\widetilde{\mathcal{C}}$ equal to the zero scheme of $t(1-(1-s)u)$.  This is flat over $\widetilde{S}$, yet the fibers do not have constant $\delta$-invariant.  For every $s\neq 1$, the $\delta$-invariant equals $1$.  For $s=1$, the $\delta$-invariant equals $0$.  

Notice, the fiber over $s=1$ is a closed subcurve of the fiber over $s=-1$.  Thus, denote the coproduct of $s=1$ and $s=-1$ as follows, $$\nu:\widetilde{S} \to S, \ \ S = \text{Spec}\ k[y,z]/\langle z^2-y^2(1+y) \rangle, \ \ \nu^*y = s^2-1, \ \nu^*z = s(s^2-1). $$  This morphism is an isomorphism away from $s=1$ and $s=-1$, which both map to a common point $p$ of $S$.  Thus, define $\mathcal{C}\subset \mathbb{A}^2_S$ to be the closure of the image of $\widetilde{\mathcal{C}}$ away from $p$.  This is most certainly not flat, yet the fiber over every point of $S$ is a reduced plane curve with $\delta$-invariant equal to $1$.  

One important feature of this example is that $S$ is not <I>normal</I>.

<B>Hypothesis.</B>  Let $S$ be an integral Noetherian scheme that is <b>normal</b>.

<B>Proposition.</B>  For every projective, smooth $S$-scheme $X$, for every closed subscheme $\mathcal{C}$ of $X$ such that every associated point of $\mathcal{C}$ dominates $S$ and has codimension $1$ in $X$, then $\mathcal{C}$ is $S$-flat if and only if every $S$-fiber of $\mathcal{C}$ has codimension $1$ in the corresponding $S$-fiber of $X$.

<B>Proof.</B>  When $\mathcal{C}$ is empty, this is trivial.  Thus, assume that $\mathcal{C}$ is not empty.  One direction is straightforward: flatness implies constancy of fiber dimension.  It remains to prove the other direction.    

The $S$-flat locus of $\mathcal{C}$ is open in $\mathcal{C}$.  Since the local ring of $S$ at each codimension $1$ point is a DVR, and since a finitely presented scheme over a DVR is flat if and only if every associated point of the domain dominates the generic point of the DVR, the flat locus contains the fiber over every codimension $1$ point.  Thus, the closure $Z$ of the image in $S$ of the non-$S$-flat locus of $\mathcal{C}$ has codimension $\geq 2$ everywhere.  
 
Although it is a bit of a sledgehammer, perhaps the "fastest" way to finish the argument is to use the existence and properties of the relative Hilbert scheme of $X/S$. (Definitely there is also an argument via local algebra and / or using Raynaud-Gruson.)

Over $S\setminus Z$, the family $\mathcal{C}$ defines a section of the relative Hilbert scheme of $X/S$.  Since the Hilbert scheme is a disjoint union of projective $S$-schemes, the closure $S'$ of the image of this section is projective over $S$.  After base change to $S'$, there is a flat extension $\mathcal{C}'$.  Since $X$ is $S$-smooth, also $\mathcal{C}'$ is a Cartier divisor in $X'=X\times_S S'$.   However, for every point $s$ of $S$, for each point $s'$ of $S'$ over $s$, the Cartier divisor $\mathcal{C}'_{s'}$ in $X_{s'}$ is a positive linear combination of prime Cartier divisors that equal the irreducible components of $\mathcal{C}_s$.  Since the total degree (with respect to some ample invertible sheaf) is constant over $S'$, also the positive coefficients of this linear combination are bounded.  Thus, the morphism $S'\to S$ has finite fibers.  

Every proper morphism with finite fibers is a finite morphism.  Since $S$ is normal, every finite, birational morphism from an integral scheme $S'$ to $S$ is an isomorphism.  Indeed, the local ring $\mathcal{O}_{S',s'}$ is intermediate between $\mathcal{O}_{S,s}$ and every localization $\mathcal{O}_{S,t}$ at a codimension $1$ point $t$ that specializes to $s$.  Since $S$ is normal, the local ring $\mathcal{O}_{S,s}$ equals the intersection of all such local rings $\mathcal{O}_{S,t}$ in the fraction field.  Thus, $S'\to S$ is an isomorphism. In other words, already $\mathcal{C}$ is $S$-flat. <B>QED</B>

Back to the setting of the original question, for an open subscheme $U$ of $X$ that is dense in every $S$-fiber, let $\mathcal{C}_U$ be a closed subscheme of $U$ whose associated points dominate $S$ and are codimension $1$ in $U$, and such that every $S$-fiber of $\mathcal{C}_U$ has codimension $1$ in the corresponding $S$-fiber of $U$.  Denote by $\mathcal{C}$ the closure of $\mathcal{C}_U$ in $X$.  Then $\mathcal{C}$ satisfies the hypotheses of the proposition.  Thus, $\mathcal{C}$ is $S$-flat.  Therefore, also $\mathcal{C}_U$ is $S$-flat.