Why do we need the absolute value signs when integrating the square of a function?

Because complex-valued functions are used. The square of a complex number need not be non-negative.


Besides the complex-valued case, I suspect it also has to do with the existence of other Lp spaces; Wikipedia gives the general definition as

$$ \|f\|_p = \left(\int_S |f|^p d\mu\right)^{1/p} $$

Since the absolute value symbols are redundant only for even integral $p$, omitting them disrupts the uniformity of the notation without buying a whole lot.