Think of it in terms of density. We split the sphere into disks. Each disk has mass dm and volume dv. The disks and the sphere must have the same density, so mass divided by volume is the same for both. This means dm/dv=Mass of sphere/volume of sphere. So dm =M dv/volume of sphere.
I didn't understood how you substituted for dm,
Think of it in terms of density. We split the sphere into disks. Each disk has mass dm and volume dv. The disks and the sphere must have the same density, so mass divided by volume is the same for both. This means dm/dv=Mass of sphere/volume of sphere. So dm =M dv/volume of sphere.