Note that all-pass filters with a perfectly constant magnitude response over the whole frequency range are realizable. A first-order discrete-time all-pass filter has the following transfer function:
$$H(z)=\frac{1-az^{-1}}{a^*-z^{-1}}\tag{1}$$
If $|a|>1$, the system $(1)$ is causal and stable. It is straightforward to show that
$$\left|H\left(e^{j\omega}\right)\right|=1,\qquad\forall\omega\tag{2}$$
i.e., the system's magnitude response is constant.
What is not possible is to have a constant magnitude response over only a part of the possible frequency range $[0,2\pi]$ (or, in continuous time, $(-\infty,\infty)$).
This can be seen as follows. First, design an ideal frequency-selective filter by computing the IDFT of some ideal frequency response (with a constant gain in the pass band(s), and a gain of zero in the stop band(s)). Let's consider discrete-time filters, but the discussion is basically the same for continuous-time filters. Let the resulting ideal impulse response be $h_{id}[n]$. First, we shift that impulse response to the right to have most of its energy at positive indices $n>0$:
$$\tilde{h}_{id}[n]=h_{id}[n-n_0],\qquad n_0>0\tag{3}$$
In order to obtain a causal filter, we need to multiply that shifted impulse response by a sequence $f[n]$ satisfying
$$f[n]=\begin{cases}0,&n<0\\1,&n>n_1\ge 0\end{cases}\tag{4}$$
with some non-negative $n_1$. The values of $f[n]$ between $n=0$ and $n=n_1$ can be chosen arbitrarily, but in practice we would choose them such that $f[n]$ increases monotonically in the interval $[0,n_1]$. The final impulse response of our causal filter is
$$h[n]=\tilde{h}_{id}[n]f[n]=h_{id}[n-n_0]f[n]\tag{5}$$
Note that $h[n]$ is still infinitely long.
In the frequency domain this corresponds to
$$H(e^{j\omega})=\left(H_{id}(e^{j\omega})e^{-jn_0\omega}\right)\star F(e^{j\omega})\tag{6}$$
where $\star$ denotes convolution. This convolution destroys the piecewise constant property of the original frequency response $H_{id}(e^{j\omega})$, and the magnitude of the resulting causal frequency response $H(e^{j\omega})$ is neither piecewise constant, nor does it have infinitely sharp transitions.