TITLE: Flatness of relative canonical bundle
QUESTION [9 upvotes]: I was wondering if there is any general theorem, which guarantees the flatness of $\omega_{X/B}$ over $B$ for a flat morphism $f : X \to B$ of schemes of finite type over $\mathbb{C}$ with equidimensional fibers. I am specially interested in statements which apply to the case of non-reduced $B$. Here by $\omega_{X/B}$ I mean $h^{-n}(f^! \mathcal{O}_B)$ where $n$ is the relative dimension of $f$ and $h^{-n}$ means the cohomology of the complex at the $-n$-th position.

REPLY [8 votes]: It sounds like you may want Exercise 9.7 in Hartshorne's "Residues and Duality".  I paraphrase the statement:

Exercise 9.7 (RD):
Let $f: X \to B$ be a flat morphism of finite type of locally Noetherian preschemes.  Then, $f^!(\mathcal{O}_B)$ has a unique non-zero cohomology sheaf, which is flat over $B$, iff all the fibers of $f$ are Cohen-Macaulay schemes of the right dimension.  Moreover $f^!(\mathcal{O}_B)$ is isomorphic to (a shift of) an invertible sheaf (on $X$) iff all the fibers of $f$ are Gorenstein schemes of the right dimension.

In particular, this addresses the case you mention in your comment ($f$ Gorenstein), since then $f^!(\mathcal{O}_Y)$ is locally free on $X$ and, since $f$ is flat, certainly flat over $B$.
[Aside: I believe I learned this reference from Brian's book "Grothendieck Duality and Base Change", which I think also contains a proof of this.]