Because the structure of the soil, due to the size of the particles, inhibits rapid drainage. Garden soil usually contains too much clay to work in containers. The shape of clay particles allows them to fit tightly together, preventing water from draining away and air from entering. Both air and water are needed to enable plants to grow healthy root systems.
Excess moisture in a container can drain away only through the hole or holes in the bottom of the container. It can't spread out horizontally very much due to the contaoner's sides. In open ground, however, excess moisture can spread horizontally without constraint, as well as down into the depths of the soil.
Potting mixes, whether they contain any actual soil or not, have a coarse structure. If soil is used as one of the components, it should be high-quality topsoil that contains a lot of humus, which is partially decomposed vegetable matter. You can add this to your own potting soil recipe by adding your homemade compost, but you'll will want to avoid sifting your compost too finely. Larger pieces of bark and other materials create spaces to allow the water to drain away quickly and air to enter.
In addition to compost and topsoil, other components can be materials like coarse sand or fine bits of gravel, perlite, peat moss, etc. added in varying proportions to produce the correct pH for the species of plants that will be grown.
Does that help?
"Isn't it enough to see that a garden is beautiful without having to believe that there are fairies at the bottom of it too?" - Douglas Adams