first of all let us see the definition of moment of inertia
now i will do this with the help of an example
for eg: we have to find the kinetic energy of a circular body rotating about it's centre of mass with angular velocity w(omega)
now total kinetic energy = sum of kinetic energy of all particles
= 1/2m1v12 + 1/2m2v22 + 1/2m3v32 ..............
= 1/2m1r12w2 + 1/2m2r22w2 + 1/2m3r32w2........... (as v = rw where r is the distance of the particle from axis of rotation(centre of mass in this case).
=1/2(m1r12 + m2r22 +m3r32 ...........) * w2
1/2 * I * w2
therefore we see that I i.e moment of inertia about an axis is the sum of products of the mass of the particles and square of thier distance from that axis (centre of mass in this case) (definition)
So when we integrating we take a small particle of mass dm & measure it's distance from the axis chosen & then square it therefore the integral becomes r2dm
therefore it is now clear from definition that r is always the distance of the particle of mass dm from the axis and not some other arbitrary r
I HOPE I'VE CLEARED YOUR DOUBT