It seems to me that although dimensional analysis is useful for demonstrating when a physics equation is wrong (when the dimensions are inconsistent), there is little justification for how it is often used to show that a given equation is correct. I'll motivate this claim with an example I went over in a class I'm TAing. Generally speaking, my question is: How (and under what conditions/assumptions) can we know that a functional relationship predicted by dimensional analysis, specifically by Rayleigh's method (https://en.wikipedia.org/wiki/Rayleigh%27s_method_of_dimensional_analysis), is the unique functional relationship that can hold between a given set of quantities?
Consider a column of stationary fluid in Earth's gravitational field. We'd like to find a formula for $\Delta P$, the increase in pressure that is measured when moving from the surface of the fluid to a point at depth $h$. Assume that we know that $\Delta P$ depends on only three variables: The depth $h$, the mass density $\rho$ of the fluid, and the acceleration of gravity $g$. These quantities have dimensions of:
$$\Delta P : [M][L]^{-1}[T]^{-2}$$ $$\rho : [M] [L]^{-3}$$ $$g : [L][T]^{-2}$$ $$h : [L]$$
Here, $[M]$ is mass, $[L]$ is length, and $[T]$ is time. Now, the standard argument in dimensional analysis goes as follows (this is basically Rayleigh's method of dimensional analysis). We suppose the equation for $\Delta P$ has the form
$$\Delta P = k \rho^a g^b h^c,$$
where $k$, $a$, $b$, and $c$ are all dimensionless constants. Now, for this equation to be meaningful, the dimensions on the left and right sides must be the same. To ensure this, we can replace each quantity in $\Delta P = k \rho^a g^b h^c$ with its corresponding dimensions, yielding:
$$[M][L]^{-1}[T]^{-2} = ([M] [L]^{-3})^a ([L][T]^{-2})^b ([L])^c = [M]^a [L]^{-3a+1+c} [T]^{-2b}$$
For the dimensions to be the same on both sides, we have to have $a=b=c=1$, and thus $\Delta P = k \rho g h$ for some dimensionless $k$.
At this point, we've certainly shown that $\Delta P = k \rho g h$ is a possible, dimensionally consistent formula for the pressure change. But I don't see how this formula is at all unique. For me, the biggest unjustified assumption enters when we assume that $k$ must be dimensionless. Even if we know that the only variable dimensionful quantities that $\Delta P$ depends on are $\rho$, $g$, and $h$, I don't understand how it follows that $\Delta P$ can't depend on one or more dimensionful constant. But the values we get for $a$, $b$, and $c$ will depend on what dimension we suppose that $k$ has. So if we can't pin down the dimension (or lack thereof) of $k$, then we can't fix $a$, $b$, and $c$, and so we've made no progress beyond the initial assumption $\Delta P = k \rho^a g^b h^c$.
When considering Newton's law of gravitation from the perspective of dimensional analysis, this ambiguity manifests itself in the opposite way. In order to derive the proportionality $F = G m_1 m_2 / r^2$ in the same way as we did $\Delta P = k \rho g h$ (by assuming that $F = G m_1^a m_2^b r^c$), we must assume that our constant $G$ has dimensions $[L]^3 [M]^{-1} [T]^{-2}$. Why is a dimensionful constant reasonable in this case, but not when deriving $\Delta P = k \rho g h$? I think this is the sticky point that this one asker was getting at in their question: Dimensional analysis - When can you introduce constants that make dimensions compatible?
In that question, the answerer provides a method to determine the dimensions of $G$ to make Newton's law dimensionally consistent, but this is only after having shown that $F \propto m_1 m_2 / r^2$, without dimensional arguments. But this is a far more modest result than what is often claimed to be a consequence of dimensional considerations - namely results like $\Delta P = k \rho g h$, or $T \propto \sqrt{l/g}$ for the period of a pendulum as a function of $g$ and its length $l$.
So is there an insight missing in my analysis, which would clear up these ambiguities and ensure that dimensional analysis produces a unique functional form for the relationship between a set of quantities? Or is dimensional analysis just often used in ways that aren't always justified?