Wizards are described as only being able to copy Wizard spells in the spellbook sidebar, and the available sources only appear to be one of four locations:
- A spell in another caster's spellbook
- A spell on a scroll
- A spell in your own spellbook (reduced cost)
- A spell you currently have prepared (reduced cost)
Nevertheless, you're still restricted to Wizard spells in your Wizard spell book. You couldn't add cure wounds to your Wizard spellbook, even if you were a Bard, had the spell prepared, found a scroll for the spell, or even somehow found a spellbook with cure wounds in it.
Furthermore, you can only copy spells into your spellbook, not in small part due to the fact that copying a spell is synonymous with understanding and learning to cast a spell. If you cannot do the latter (because the spell isn't one you can learn) then you certainly cannot do the former.
As I've mentioned above, I consider "spellbook" to be primarily a description rather than an actual specific object. The cost difference between "book" and "spellbook" in the PHB isn't justified anywhere, but to me it reads merely as a quality and size distinction. A "book" can be any book of any length with any quality. It could be a 20 page pocket prayer manual on unbleached papyrus, gut-bound to a wooden shingle. A "spellbook" is high quality book (leather bound with vellum pages) that's large enough to hold 100 pages of spells.
Thus, when you say, "the book has the fireball spell in it" you've already determined that its a spellbook. If you find a book that is not high quality that contains a written spell on it in spellbook format, it would not be useful and you would say, "the book describes the fireball spell, but as you study it you find it is imperfect and lacks vital details that have been lost due to the quality of the manuscript."
Similarly, a Wizard spell copied by a non-Wizard would be useless. It would lack the meaning and detail that the original caster needed to prepare the spell, and any other caster studying the work would not have enough information to translate the spell and copy it into their own spellbook.
On the other hand, if you attempt to copy a spell without meeting the proper requirements (having the spell on your class spell list, spending the time and the inks, using a book of sufficient quality) then you can't use the copy to prepare the spell. That tells me it's fundamentally incomplete and, therefore, not a copy and then also not a spell in a spellbook. Therefore, "copy a spell" and "add a spell to one of my spellbooks" are also synonymous terms.
A Warlock would similarly only be able to copy any Ritual spell he or she finds into his or her Book of Shadows from similar sources. A character with the Ritual Caster feat would only be able to copy ritual spells of the class he or she selected when choosing the feat.