This question already has an answer here:
Wizards, for example, are explicitly stated to copy spells from scrolls, and can only learn spells from scrolls. However, the Eldritch Invocation Book of Ancient Secrets is very general about how ritual spells can be learned:
On your adventures, you can add other ritual spells to your Book of Shadows. When you find such a spell, you can add it to the book if the spell’s level is equal to or less than half your warlock level (rounded up) and if you can spare the time to transcribe the spell.
"Finding such a spell on your adventures" seems very general. Specifically, could learning spells from another caster qualify?