Cosmic rays generate free neutrons by spallation from nuclei in Earth’s atmosphere, Earth’s crust, and Earth’s deep interior. Not many cosmic rays reach the deep interior, because the Earth is a pretty good shield.
Solid rock is opaque to neutrons for the same reason that clouds are opaque to light. Consider that storm clouds are made of water droplets and ice crystals, which are almost totally transparent. Why, then, does it get dark under a storm cloud? The water droplets and ice crystals in the cloud are very efficient scatterers of light, and so light anywhere within the cloud is reoriented in a random direction, just as likely to be going back up towards the sun as to continue down towards the ground. As the cloud gets thicker and thicker, the fraction of sunlight that diffuses through to the bottom of the cloud gets smaller and smaller. Clouds don’t ever completely block sunlight (on Earth), but our mostly-transparent ocean does have the bathypelagic zone where no sunlight penetrates.
The mean free path of a neutron in rock depends on the chemical makeup of the rock, and the probability that the neutrons will capture versus scatter from each chemical species in the rock, and its density. But consider that a nuclear reactor, which contains a lot of free neutrons, is effectively shielded by tens of meters (not hundreds of meters) of water and concrete. The mean free path of a neutron underground is going to be more like ten meters than like a kilometer. Neutrons from the surface are not going to diffuse down to Earth’s core.
A neutron which leaks upward out of Earth’s surface is going to have scattered enough times that it’ll have roughly the same temperature as Earth’s surface, and so will behave like a component of Earth’s atmosphere. The scale height for atmospheric neutrons will be more like the scale height for hydrogen and helium than like the scale height for nitrogen or oxygen, so the neutrons can diffuse up into the exosphere. The fraction of ground-level atmospheric neutrons which escape to the exosphere before decaying or being captured (mostly by nitrogen) would be a nice homework problem.