My understanding is that when a spell is known or prepared via one of your class features, or if you cast it via a class feature, it's considered a "class spell" (sorcerer spell, cleric spell, etc.) for you. If you cast it via some method outside your class (items, etc.), it isn't considered a spell from your class.
For clarity, some class features care about whether or not a spell is a 'class' spell (emphasis mine):
Wild Magic Surge for Wild Magic sorcerers can only trigger "[…] immediately after you cast a sorcerer spell […]".
Overchannel for School of Evocation wizards can only be used "when you cast a wizard spell […]"
Empowered Evocation for School of Evocation wizards can also only be used on "[…] any wizard evocation spell you cast".
Rod of the pact keeper gives a bonus "[…] to the saving throw DCs of your warlock spells".
Contrast with a feature like Blessed Healer for Life Domain clerics that just use the language of "When you cast a spell […]", and you'll see why I believe there's an important distinction as to whether or not a spell instance is a 'class' spell.
However, comments on this answer made me question where my understanding of what makes a spell instance a 'class' spell comes from, and I'm not sure of a concise spot that explains it. What are the rules that govern what is or is not considered a class spell when cast?
Of particular concern is whether or not a spell is, in all instances, a class spell once you've obtained it from your class. For example, if you were a wizard that had magic missile both prepared and in your spellbook, would any instance of magic missile you cast be considered a wizard spell, even if it was cast by way of, say, a wand of magic missile?
A spell is considered a Class Spell if it's listed in the class' spell list
While not explicitly defined this way, there is evidence of it being implied:
With how the above features are worded, you may infer that any spell that is not on the class' spell list in PHB 207-211, is not a class spell, because the only way to add a spell to your class spell list is through similar features as above. And that, through inversion, any spell in a class' spell list is a class spell.
Jeremy Crawford weighs in with a tweet here: