This is honestly a pretty narrow set of circumstances if you take the Divine/Arcane/Primal divide into account. Also, it doesn't apply well to divine casters at all.
As per the PHB rules, a divine caster (AKA Cleric or Paladin) already "knows" every spell of a certain level. Therefore, a cleric cannot teach a cleric any new spells, they both have the same spells known. Teaching a Paladin a cleric only spell enters into the territory of simply expanding the paladin list, and also these spells are "inspired by the gods" so that whole thing is a little tricky.
Allowing Sorcerers or Warlocks to teach spells falls into the same fluff problem. Warlocks and Sorcerers get their spells, but they don't study and learn them. For a sorcerer it becomes teaching someone how to breathe, at a certain point you either can do it or not, you can't explain how to someone. Since Warlocks get their spells from other entities it depends a lot on their fluff, but if you go with them just suddenly "knowing" magic it could be something they can't teach.
So... bards and wizards are the big arcane question and Druids and Rangers. I think Druids work the same as clerics, so they wouldn't have any need to teach beyond the circle of the land extra spells... which you could conceivably share but that might upset the balance. Also, Bards using the power of song and word is very different from the wizards arcane formulas in my opinion, so I would not allow Bards and wizards to share.