Let $f:X\rightarrow S$ be a morphism of schemes. The definition of an effective Cartier divisor in $X/S$ given in Katz-Mazur (what is called relative effective Cartier divisor in the Stacks Project) is: a closed subscheme $i:D\hookrightarrow X$ such that the ideal sheaf $I(D)$ is invertible and $f\circ i:D\rightarrow S$ is flat.

I have two (possibly related questions).

Question 1: Is the flatness of $f\circ i$ equivalent to flatness of the $\mathscr{O}_X$-module $i_*\mathscr{O}_D\cong\mathscr{O}_X/I(D)$ over $S$?

I believe the answer to this question is yes, but only because $i$ is a closed immersion. Flatness of $f\circ i$ means the morphism $\mathscr{O}_{S,f(i(x))}\rightarrow\mathscr{O}_{D,x}$ is flat for all $x\in D$, while flatness of $i_*\mathscr{O}_D$ over $S$ means for each $x\in X$, $(i_*\mathscr{O}_D)_x$ is flat over $\mathscr{O}_{S,s}$ (or equivalently, $i_*\mathscr{O}_D$ is a flat $f^{-1}\mathscr{O}_S$-module). Because $i$ is a closed immersion, $(i_*\mathscr{O}_D)_x$ is either zero or $\mathscr{O}_{D,x}$ according as $x$ is or isn't in $D$. The equivalence of the two conditions follows from this. But surely for a general morphism $D\rightarrow X$ (not necessarily a closed immersion), flatness of $D$ over $S$ and flatness of $i_*\mathscr{O}_D$ over $S$ are different, right?

Question 2: In Katz-Mazur, the claim is made (albeit implicitly) that in the sequence

$0\rightarrow \mathscr{O}_X\rightarrow I(D)^{-1}\rightarrow i_*\mathscr{O}_D\otimes_{\mathscr{O}_X}I(D)^{-1}\rightarrow 0$,

which is obtained by applying the exact functor $-\otimes_{\mathscr{O}_X}I(D)^{-1}$ to the exact sequence $0\rightarrow I(D)\rightarrow\mathscr{O}_X\rightarrow i_*\mathscr{O}_D\rightarrow 0$ (here $I(D)^{-1}$ is the inverse of the invertible $\mathscr{O}_X$-module $I(D)$), the quotient is $S$-flat. I don't see why this is. I can't even think of an algebraic fact to which it can be reduced. Maybe it helps to think of the quotient as $I(D)^{-1}/1_DI(D)^{-1}$, wher $1_D$ is the section defining the injection $\mathscr{O}_X\rightarrow I(D)^{-1}$.

The reason I say "implicitly" above is because, while the claim in my second question is never made explicitly, after defining effective Cartier divisors and writing down the exact sequence above, KM considers pairs $(\mathscr{L},\ell)$ consisting of an invertible $\mathscr{O}_X$-module $\mathscr{L}$ and a regular section $\ell$ of $\mathscr{L}$, meaning the associated map $\mathscr{O}_X\rightarrow\mathscr{L}$ is injective, such that in the sequence

\begin{equation*} 0\rightarrow\mathscr{O}_X\rightarrow\mathscr{L}\rightarrow\mathscr{L}/\mathscr{O}_X\rightarrow 0 \end{equation*}

the quotient is $S$-flat. Ultimately they describe a bijective correspondence between isomorphism classes of such pairs and effective Cartier divisors, given by $D\mapsto (I(D)^{-1},1_D)$. This is why I think the claim about $S$-flatness of the quotient in the exact sequence of Question 2 is being made implicitly.

-

As for question two, use the fact that $I(D)$ is locally free (of rank one, although that doesn't matter) over $\mathcal O_X$. This means that locally on $X$, $i_* \mathcal O_D \otimes I(D)^{-1}$ is isomorphic to $i_* \mathcal O_D$. Since the latter is flat over $S$, and flatness can be tested locally (even on stalks), the former is also flat over $S$.