Symbiotic relationships have no explanation other than - it happened. So? How did it happen?
On a
very simple level, symbiosis follows that species that have some ecological proximity begin to evolve traits that work off each other. While these traits make it
easier for them to survive, they are not
critical to survival initially. However, ecosystems change and stressors are introduced, it may become critical, keeping the symbiosis and killing of those without it.
To give a couple examples:
Predator/prey encourages an evolution of traits to make it easier to catch or escape. If a member of a prey species develops a trait that makes it easier to escape the predator, they’re more likely to escape as the predator kills others. That trait then can be passed on. However, as
that trait takes over, the predator may find itself at a disadvantage, but any traits that make the predator more fit to hunt the prey, particularly its new trait, will make it easier for those organisms to catch, eat, and survive. Over time, this back-and-forth effectively brings out two new species, possibly even leaving the older ones extinct.
We can also consider the tree/fungal relationship. It’s possible that an ecosystem can easily support trees without fungi due to the relative richness of the soil. Fungi exist but aren’t critical. However, let’s say a new species is introduced that is rather aggressive in taking nutrients from upper layers of the soil. The trees in the current ecosystem may struggle with this new species. However, those trees that evolved deeper roots may be able to reach still-nutrient-rich-soil below the contested area. For other trees, they may have evolved a way to work with fungi to get nutrients, requiring less from the now-depleted soil. Those trees that neither evolved deeper roots nor evolved some form of symbiosis with fungi are now killed off, and we thousands of years later are none-the-wiser.
Those are just a couple theoreticals, but we even see elements of this in human society today. Domestication can be thought of as a form of symbiosis, and it’s at the core of much of our agriculture and pet industries and used to be core to hunting (less so now). Invasive species are another case. Sometimes it wrecks ecological damage (e.g. Burmese pythons in the Everglades), but sometimes it all works out (e.g. the sword fern as decoration).
In the end, symbiosis is arguably one of the
strongest cases for evolution by natural selection, as natural selection is
very well suited to explaining the phenomena, and we obviously have observable cases in domestication and invasive species. Even beyond evolution itself, we have other fields of biology dedicated to understanding these relationships, like ecology and its many sub-fields. That is an
excellent place to start if you want to look more into this. Other fields (e.g. some forms of geology) might be more suited to the actual historical development, since ecology is a bit more here-and-now (at least how I studied it before making a drastic shift to computer science).