Here is a stronger result (related to this thread). I claim that the dihedral group $D_n$ is decomposable if and only if $n\equiv 2\pmod{4}$. (In particular, when $n=24$, we have $n\not\equiv 2\pmod{4}$, so $D_n=D_{24}$ is indecomposable, so you can't write $D_{24}=D_3\times D_4$.) The case $n\in\{1,2\}$ is easy. We now assume that $n\geq 3$.
If $D_n=A\times B$ for some non-trivial subgroups $A$ and $B$, then $A$ and $B$ are normal subgroups of $D_n$, and $A\cap B=\{1\}$. Write $D_n=\langle R,F\rangle$, where $R^n=F^2=1$ and $(RF)^2=1$ as given here. Then, the normal subgroups of $D_n$ are
$n$ odd: $\langle R^d\rangle$ where $d$ is a divisor of $n$;
$n$ even: $\langle R^d\rangle$ where $d$ is a divisor of $n$, and two more $\langle R^2,F\rangle$ and $\langle R^2,RF\rangle$.
So, if $n$ is odd, then both $A$ and $B$ are subgroups of the cyclic subgroup $\langle R\rangle$, which means $A$ and $B$ are abelian, and so $D_n=A\times B$ is abelian, which is a contradiciton.
If $n\geq 4$ is even, then exactly one of $A$ and $B$ takes the form $\langle R^2,F\rangle$ or $\langle R^2,RF\rangle$. WLOG, $A$ is of such a form. Then, $A\cong D_{n/2}$. So, $B$ must be isomorphic to the cyclic group $C_2$ of order $2$.
If $n\equiv 2\pmod{4}$, then we can take $A=\langle R^2,F\rangle$ and $B=\langle R^{n/2}\rangle$ to see that $$D_n=A\times B\cong D_{n/2}\times C_2.$$ In fact, there are exactly two ways to decompose $D_n$ into a direct product of non-trivial subgroups:
$$D_n=\langle R^2,F\rangle \times \langle R^{n/2}\rangle$$
and
$$D_n=\langle R^2,RF\rangle \times \langle R^{n/2}\rangle.$$
If $4\mid n$, then all elements of order $2$ of $D_n$ are $R^{n/2}$ and $R^kF$. But the subgroup generated by $R^kF$ is not normal, and $R^{n/2} \in A$ because $\frac{n}{2}$ is even. Therefore, $A$ and $B$ cannot exist. Hence, $D_n$ is indecomposable when $4\mid n$.