Why does dark matter form halos? Earlier questions (e.g. How does Dark Matter form a halo?) referred to the distribution of dark matter in the galaxy. My question is different (not a duplicate). I wonder why dark matter would form a halo around a galaxy at all.
Dark matter does not interact electromagnetically and therefore does not lose its kinetic energy, at least not nearly as much as normal matter. Therefore, a flying by particle of dark matter that is not on an orbit around a galaxy may change its direction, but will still fly away. In other words, dark matter that is not in the halo of a galaxy already will not be in this halo, unless somehow slowed down.
So, how does a halo form in the first place? Does a forming galaxy simply attract the dark matter that happens to be local there? Or is dark matter a decay product of normal matter in the galaxy?
Image credit: Wikipedia

 A: There are two aspects to this, one straightforward and one rather more speculative.
The straightforward one is that dark matter is weakly interacting but not non-interacting. In particular dark matter particles will undergo dynamical friction just like every other gravitationally interacting material. In effect a dark matter cloud cools by evaporation. When particles interact gravitationally a small proportion will get a high momentum just by chance, and those particles will escape the cloud carrying away excess momentum with them.
The rather more speculative bit is how primordial density differences were created in the first place, and this is normally attributed to fluctuations during inflation. The fluctuations measurable in the CMB are consist with this mechanism, though the whole question of inflation seems to be getting a bit vexed these days.
Later:
Having rushed into print I now see there is a closely related question How can dark matter collapse without collisions or radiation? that is possibly a duplicate.
