I would instead say that the way dimensional analysis works in the first place is based on the idea that you cannot take an arbitrary function of a dimensionful quantity, only a dimensionless quantity.
A dimensioned quantity can be regarded in a couple of ways. In the SI units, a dimensioned quantity lives in $\mathbb R \times \mathbb Q^7$, where the real number is a sort of magnitude and the $\mathbb Q^7$ are rational-number exponents applied to the seven SI base units. The algebra defines an operation $(r_1, q_1)+(r_2, q_2) = (r_1 + r_2, q_1)$ which is a partial function, it only is meaningful when $q_1=q_2,$ and an operation $(r_1, q_1)\times (r_2, q_2) = (r_1 \times r_2, q_1 + q_2)$ which is a full function meaningful even if $q_1 \ne q_2.$
Taking an arbitrary function of such a dimensioned quantity is technically definable even when $q\ne [0,0,0,0,0,0,0].$ One could simply define that
$$\operatorname{lift}[f](r, q) = (f(r), q).$$
However this does lead to some very strange things like $x \times x \ne x^2.$ This approach does not really capture the “why” we are doing what we are doing, just the “what” we are doing.
A stronger statement which encapsulates the “why” would state that a dimensioned quantity is an equivalence class of unit-value pairs, so for example one kilogram is secretly a set that looks like, $$\{(\text{mg}, 10^6), (\text{g}, 10^3), (\text{kg}, 1), (\text{lb}, 2.20462),\dots\}.$$ Indeed these could also be stated as functions from units to reals, if that helps.
When you define a thing as an equivalence class, you can “lift” functions from the source domains to the equivalence classes only when they preserve the equivalence relation, in which case we say that the lifting is “well-defined.”
This captures the “why” much better as it gives a reason, for example, why addition can be well-defined only when the dimensions are the same.
Arbitrary functions do not have a clear well-defined way to be applied to these equivalence classes directly, of course, unless the unit is the empty unit and hence the equivalence class is just the number itself, $\{(\bullet, \pi)\}$ for example.
The result is that if you take all of your dimensionful input parameters $p_{1,2,3\dots n}$ you will find that you can form only a few dimensionless parameters $D_{1,2,3\dots \ell}$, and then for any physical quantity $P$ you will find that the most general expression can only be $$P = p_1^{q_1}~p_2^{q_2}~\dots p_n^{q_n}~f\big(D_1, D_2, \dots D_\ell\big),$$ where the choice $\{q_1\dots q_n\}$ are just any arbitrary choice of rational numbers which gets you the same dimensions as $P$, and $f$ is some arbitrary function of the dimensionless parameters.
So for example if something is falling from space to Earth, you might be interested to figure out the time it takes to do so; this depends on the starting distance $r_0$ from Earth, and the mass of earth $M$ and the gravitational constant $G$ and its initial speed $v_0$. There is only one dimensionless constant and so the fall time must have some representation like $$t = \sqrt{\frac{r_0^3}{GM}} ~f\left(\frac{r_0 v_0^2}{G M}\right),$$ for some function $f$. The reason I know this is that no other arbitrary functions are well-defined.