Consider a continuous charge distribution in volume $V'$. Draw a closed surface $S$ inside the volume $V'$.
Consider the following multiple integral:
$$B= \iint_S \Biggl( \iiint_{V'} \left[ \dfrac{\cos(\hat{R},\hat{n})}{R^2} \rho'\ \right] dV' \Biggl) dS$$
where
$R=|\mathbf{r}-\mathbf{r'}|$
$\mathbf{r'}=(x',y',z')$ is coordinates of source points
$\mathbf{r}=(x,y,z)$ is coordinates of field points
$\cos(\hat{R},\hat{n})$ is the angle between $R$ and normal to surface element
$\rho'$ is the charge density and is continuous throughout the volume $V'$
Since $\mathbf{r} \in S$, the function is not integrable in domain $V'$. So we use change of variables:
$$B= \iint_S \Biggl( \iiint_{V'} \left[ \dfrac{\cos(\hat{R},\hat{n})}{R^2} \rho'\ {r'}^2 \sin \theta' \right] d\theta' d\phi' dr' \Biggr) dS$$
$\bbox[yellow]{\text{Note that in this equation, $\theta'$ and $\phi'$ are w.r.t point $\mathbf{r} \in S $}}$
The inner volume integral is an iterated integral. While computing this iterated integral in spherical coordinates (here $\mathbf{r'}$ varies and $\mathbf{r}$ is constant), we take the origin of our spherical coordinate at point $\mathbf{r} \in S$. That is, $\mathbf{r}=(0,0,0)$
Therefore after computing this iterated integral, i.e. after applying the limits, we will not be getting a function of $(r,\theta,\phi)$ or $(x,y,z)$. Instead we will be getting a number. This means we cannot carry out the surface integral by iterated integrals. Will this fact prevent us from swapping the order of surface and volume integrals? Why? Why not?
If swapping the order of surface and volume integrals is valid:
\begin{align} B &= \iiint_{V'} \Biggl( \iint_S \left[ \dfrac{\cos(\hat{R},\hat{n})}{R^2} \rho'\ {r'}^2 \sin \theta' \right] dS \Biggr) d\theta' d\phi' dr'\\ &= \iiint_{V'} \Biggl( \iint_S \left[ \dfrac{\cos(\hat{R},\hat{n})}{R^2} \right] dS \Biggr) \rho'\ {r'}^2 \sin \theta' d\theta' d\phi' dr'\\ \end{align}
$\bbox[yellow]{\text{Here in this last equation, $\theta'$ and $\phi'$ are w.r.t. which point?}}$
Special note for the answerer
This question may or may not be related to Fubini's theorem. If it is, please give the complete statement of Fubini's theorem and please show step-by-step how my question can be explained by Fubini's theorem. Please consider that I am a graduating student of Mathematics and I am learning real analysis (single and multivariable). Please try to explain within the scope of real analysis.