Crawford's tweet on the subject indicates that it is as simple as the spell being on the caster's class' spell list:
What ultimately makes something a [class] (wiz/sorc/etc) spell? Is having it on your spell list enough, even if you're not high enough to cast/don't know it/don't cast via Spellcasting? I.E., can a level 1 Sorc Wild Magic Surge off of Luck Blade's wish despite not knowing it yet?
@SymphFan, 4:12 PM - 26 Jun 2018
A class's spell list is the list of that class's spells. #DnD
@JeremyECrawford, 5:57 PM - 26 Jun 2018
However, between tweets no longer being official rulings and feeling that there are a few gaps in that simple statement, I think it's worth enumerating the edge case rules to consider ahead of that bit of advice.
Here's the list of "how to determine if a spell is a particular class'" guidelines that I've inferred from other rules and rulings, in decreasing priority.
1. The spell is being directly cast from a non-Spellcasting/Pact Magic class feature.
This isn't explicitly stated in the books, but I believe this to be true for features like the warlock's Eldritch Invocations that allow casting particular spells that aren't on the warlock list, such as Dreadful Word allowing the casting of confusion. Confusion isn't explicitly marked as a warlock spell, and it isn't on the warlock spell list, but it seems clearly meant to be considered a warlock spell. RAI agrees, as well:
@JeremyECrawford If I am a Warlock and I use an invocation to cast a spell that's not on the Warlock list (such as Levitate, Confusion, or Slow) requiring a save, does it use my Warlock spell save DC? Also, can such a spell benefit from Rod of the Pact Keeper?
@Bloodcinder, 5:19 AM - 21 Feb 2019
The spells you cast through the Eldritch Invocations feature are meant to be warlock spells for you. #DnD
@JeremyECrawford, 5:18 PM - 21 Feb 2019
The other part of this to consider is this means that even if you learned confusion via another class (such as multiclassing into sorcerer or the like), this invocation's instance of casting it would still be a warlock spell.
I imagine this would also cover spells from monks' Way of the Four Elements' Elemental Disciplines, preventing them from being considered to be any other class' when cast that way.
2. The source of the spell specifically states it counts as a particular class'.
This one's a bit obvious. This is for cases like the bard's Magical Secrets or the cleric's Domain Spells, where it is explicitly stated that a learned spell counts as a particular class'. Only bothering listing it here for thoroughness' sake. This rule is generally the overriding exception to:
3. The spell was learned or cast via a specific class' spell list.
This one comes from the Sage Advice Compendium's official ruling in regards to Magic Initiate:
If you have spell slots, can you use them to cast the 1st-level spell you learn with the Magic Initiate feat? Yes, but only if the class you pick for the feat is one of your classes. For example, if you pick sorcerer and you are a sorcerer, the Spellcasting feature for that class tells you that you can use your spell slots to cast the sorcerer spells you know, so you can use your spell slots to cast the 1st-level sorcerer spell you learn from Magic Initiate. Similarly, if you are a wizard and pick that class for the feat, you learn a 1st-level wizard spell, which you could add to your spellbook and subsequently prepare.
In short, you must follow your character’s normal spellcasting rules, which determine whether you can expend spell slots on the 1st-level spell you learn from Magic Initiate.
Magic Initiate does not overtly declare the learned spell to count as the class' whose list you are learning it off of. However, this official ruling is stating that the spell has to be learned off of your own class' list, or else it does not count as your class'. As such, I feel this ruling is inferring that learning a spell off of a particular class' list makes it count as that class', which ties in with that initial quoted tweet from Crawford. Otherwise, I imagine the answer would state "Yes, but only if the spell you pick is on one of your classes' lists".
This also typically covers spells you've learned the usual way, through the Spellcasting/Pact Magic feature.
If none of those 3 steps above apply and the spell is still 'classless', then the "a class's spell list is the list of that class's spells" guideline comes in, and you can choose one of your classes with that spell on its list to have it count as that class'.
To run through the wand of magic missile example, point 1 doesn't apply, as it's not being cast via a class feature, it's being cast through the generic 'use a magic item' action. Point 2 doesn't apply, as the wand doesn't say it counts as a wizard (or otherwise) spell. Point 3 may apply if you've learned it from one of your classes, in which case the spell is somewhat locked in to that class. If you haven't learned it and point 3 doesn't apply, then Crawford's 'fallback' statement applies, and you may choose to have the wand of magic missiles' spellcast count as any of your classes which have magic missile on their list.
This also syncs up with Crawford's tweets stating that effects that trigger off of 'class spells' can trigger off of wands:
@JeremyECrawford when a wild magic sorcerer uses a wand of magic missiles, can he trigger a Wild Magic Surge?
@TheMaDdi3, 3:18 AM - 5 May 2016
@JeremyECrawford, 2:57 PM - 9 May 2016