This is true provided that the source is Cohen--Macaulay (e.g. regular) and the base is regular. This is sometimes called miracle flatness. (It can be found as Thm. 23.1 of Matsumura's CRT.)
It generalizes the fact that a non-constant map from a reduced curve to a smooth curve is necessarily flat.
(In the case when the fibre dimension is zero, it is related to the Auslander--Buchsbaum theorem, which says that a f.g. faithful Cohen--Macaulay module over a regular local ring is necessarily free.)
Added: As Georges Elencwajg points out in a comment below, in the context of miracle flatness I should require that we are working with locally finite type schemes over a field.