What makes a spell being cast considered to be a {class} spell?

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?