The density of the lower rod at point $u$ is NOT $f(g(u))$. It is $f(g(u))\cdot |g'(u)|$ as explained a few moments later (it has absolute values since we're talking about densities). So, the youtuber's explanation around the 18.45 minute mark that the two segments have "same density but different lengths" is incorrect and misleading. It should say "same mass but not necessarily same lengths", and hence not necessarily same densities (which is ultimately what they arrive at, but I think there's a good 30s of confusion in the middle of the explanation).
Actually, I've already written an answer here about a very similar question. I think the first half of that answer is relatively understandable because I restricted myself to use very few formulas; the second half of the answer is more technical (because OP asked how things generalize, so I gave the details there) so you can skip that if you wish.
Anyway, I'll try to rephrase the argument restricting to the 1-dimensional case. So, we consider two rods, and a function $g:L\to U$, which maps the lower rod onto the upper rod. For the sake of intuition, you may want to assume $g$ is bijective (i.e invertible); and to visualize things you may want to think of the rods as being an elastic material, so that the function $g$ either stretches/squishes parts of the rods in a certain fashion; so it is something which deforms the original rod.
Let us suppose that the upper rod has a density function $f:U\to\Bbb{R}$, and assume it's nice and continuous, and that the lower rod has continuous density function $\rho:L\to\Bbb{R}$. Also, suppose $g$ is $C^1$. Our task is to find the relationship between $f,g,\rho$. Now consider a point $u\in L$ on the lower rod, and a small interval $[u,u+\delta]$ containing the point $u$. Note that the function $g$ since we're thinking of it merely as a continuous deformation, it had better conserve the mass, meaning:
\begin{align}
&\text{mass of the segment $[u,u+\delta]$ of lower rod}\\
&= \text{mass of the deformed segment $g([u,u+\delta])$ in the upper rod}
\end{align}
Suppose $\delta>0$ is very small. Then, by continuity of $\rho$, it follows that the density of the lower rod at each point of the segment $[u,u+\delta]$ is approximately $\rho(u)$. So, the LHS of the equation above is approximately $\rho(u)\cdot \text{length of the interval $[u,u+\delta]$}$
Next, since we assumed $g$ to be continuous, it follows that the deformed interval $g([u,u+\delta])$ will also be a small interval containing the point $g(u)$. Thus, the density function $f$ is approximately constant here with value $f(g(u))$. So, the mass of this rod is approximately $f(g(u))\cdot \text{length of $g([u,u+\delta])$}$. Thus, plugging in these approximations to the equation above we get
\begin{align}
\rho(u)\cdot \text{length of $[u,u+\delta]$} &\approx f(g(u))\cdot \text{length of $g([u,u+\delta])$}
\end{align}
Thus, rearranging,
\begin{align}
\rho(u)&\approx f(g(u))\cdot \frac{\text{length of $g([u,u+\delta])$}}{\text{length of $[u,u+\delta]$}}
\end{align}
As we let $\delta\to 0^+$, it is highly likely that the RHS approaches $f(g(u))\cdot |g'(u)|$ (the absolute values are there since we're talking about ratios of lengths; if I had merely written $\lim\limits_{\delta \to 0^+}\frac{g(u+\delta)-g(u)}{\delta}$, then this would indeed be $g'(u)$).
Therefore, we have
\begin{align}
\rho(u)&=f(g(u))\cdot |g'(u)|
\end{align}
In other words,
\begin{align}
\text{density of lower rod at point $u$}&=
(\text{density of upper rod at point $g(u)$})\\
& \times (\text{limit of ratio of lengths due to the mapping $g$, at point $u$})
\end{align}
This last formula extends verbatim in logic to any number of dimensions (as I explained in my linked answer; simply replace "length" in this equation by "$n$-dimensional volume")
Finally, a word of caution. What this answer tells you is the heuristics (very valuable one) for the change of variables formula. This reasoning is definitely not a proof, but it's a good indication of how one might arrive at the correct formula (in the one-dimensional case if we assume $f$ is continuous and $g$ is $C^1$ then the proof is a triviality using the FTC, but in higher dimensions this is a VERY non-trivial theorem to prove correctly).