That's because the homogeneity and isotropy of the Universe (the "Cosmological Principle") is only assumed — and observed — to be valid on large scales.
The density fluctuations are assumed to have arosen during the epoch of inflation, and have their origin in primordial quantum mechanical uncertainties in positions and momenta of whatever field was around at that time. That is, a successful inflationary model should predict a homogeneous and isotropic Gaussian$^\dagger$ random fluctuation field, because this is what we observe in the cosmic microwave background, and because gravitational collapse of structures out of such a field is more or less consistent with observed structures. We can see that on small scales, the Universe is neither homogeneous nor isotropic (for instance, we're here), while on large scales (i.e. $\gtrsim1/2$ billion lightyears) it does seem to hold true.
$^\dagger$Some models consider non-Gaussian fields.