The Question: The unique thing here is that one variable is proportional (either directly or inversely) to multiple variables. If each such relation is expressible as an equation, your question boils down to how to ‘combine’ all of the relations? That is, to reduce them to a single equation?
Now, let's focus on the first equation. Think of $F \propto m_1 m_2 $ as saying that $F$ is proportional to the product $m_1 m_2$ only when all other factors (or variables, synonymously) are fixed (for example, the distance $r$). How do we write this as an equation? It is $F(m_1, m_2) = c m_1 m_2$, where $c$ is the constant of proportionality, the variables are $m_1$ and $m_2$, and $F$ is a function of $m_1$ and $m_2$ (mathematically, we write $F(m_1,m_2)$). Since right now we are just modelling the $F \propto m_1 m_2$ relation, all other variables are constant and hence don’t appear in this equation (so, in particular, we don't see our distance term $r^2$, even though we physically know that it should be there).
But even though it doesn’t appear explicitly, this is because the distance term is ‘hidden’ in the constant $c$. Mathematically, let me show you that it’s ‘hidden’ in c: note that we can break $c$ as the product of two constant terms, $c = \frac{c_1}{r^2}$, and indeed we explicitly see the constant $1/r^2$ term + another constant term, $c_1$, chosen such that the above equality holds.
This might seem stupid, but you should be saying to yourself: “in this one proportionality relation, $r$ is assumed unchanging and is thus a constant, and so I hide $r$ in my proportionality constant $c$ because it’s a constant!” You’re putting like terms with like, constants with constants.
Similarly with the second relation: Similarly, we get from your other relation that $F(r) = \frac{b}{r^2}$, where $b$ is the constant of proportionality, and this time no mass term appears because we are assuming it to be constant, and thus it also ‘hides’ in the constant $b$.
The Upshot: Ok, now we want to combine these - physically, this means we want to think of force as a function of all three of the variables, $F(m_1, m_2, r)$ (that is, none of these are assumed constants now). Mathematically, we want an equation for $F(m_1, m_2, r)$ which better include all three as variables (and not constants).
Thus, if we derive using the first equation and ‘revealing’ $r^2$ (so that we group it with the variables and not the constant term), we get $F = c m_1 m_2 = c_1 \frac{m_1 m_2}{r^2}$, where this second equality is because of how we defined $c_1$ above. We do the 'revealing' because $r^2$ is now treated as a variable: it is treated as a constant anymore.