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" (Sorcerersorcerer spell, Clericcleric 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 Sorcererssorcerers can only trigger "[...] immediately after you cast a sorcerer spell [...]".
Overchannel for School of Evocation Wizardswizards can only be used "when you cast a wizard spell [...]"
Empowered Evocation for School of Evocation Wizardswizards can also only be used on "[...] any wizard evocation spell you cast".
Rod of the Pact KeeperRod 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 ClericsDomain 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 Wizardwizard that had Magic Missilemagic missile both prepared and in your spellbook, would any instance of Magic Missilemagic missile you cast be considered a Wizardwizard spell, even if it was cast by way of, say, a Wand of Magic Missilewand of magic missile?