There are many spells which explicitly target creatures:
Choose one creature within range
The target creature is normally supposed to make a saving throw in this case.
What happens when the caster chooses a creature, that is actually an object? For instance, a scarecrow, a mannequin, an illusion, or a corpse.
An evil mage is hiding in the bushes. He casts an illusion of himself on the road, using the Silent Image spell. A PC sorcerer walks down the road, sees the illusion and casts Magic Missile on it.
A cleric is standing near a pile of dead bodies. He has suspicions that a few corpses are actually undead creatures. He casts Sacred Flame on every corpse, see which if them succeed, hence, reveals the undead.
A wizard casts Acid Splash on a mannequin, trying to damage it with acid.
Possible outcomes I can think of are:
- The caster cannot even try to cast the spell, regardless of their information about what the target actually is.
- The caster tries to cast the spell, the casting fails, not expending the spell slot.
- The caster casts the spell, it expends the spell slot, then fails.
- The caster casts the spell, but it hits the original and not the illusion.
- The caster casts the spell, it flies to the target illusion but deals no damage to it (passes through it).
References in the rules and Sage advice
I was trying to investigate, but it didn't make things clearer:
Does magic missile hit silent image's illusory creature? has an answer, that Magic Missile won't hit. It says nothing about if it can be targeted at all, it leaves it up to the DM.
Magic Missile automatically finds the original, even when the caster targets an illusion. At least when the illusion was created by the Mirror Image spell. Now confirmed by Jeremy Crawford. This supports the counter-intuitive option 4.
on the other hand
- Casters don't automatically know when a spell fails, if there were no perceivable effects (let's say you can try to cast the Command spell on an illusion). That assumes that casters can waste their spells on illusion, which means they at least can target it. This supports options 3 and 5.