It's irrelevant: humanoid is a type of creature (see the first chapter of the Monster Manual). Undead and constructs are different types and are ineligible targets. As are giants, dragons, etc.
In short, if it doesn't say humanoid in the monster stat block immediately under the name you can't cast Magic Jar on them.
Just in case it comes up: a Druid currently wildshaped is a beast or elemental, not a humanoid. Similarly, any creature under a Polymorph effect has the type they have been polymorphed into. So you can Polymorph the vampire to a humanoid and then Magic Jar them.
You Would be Almost Unkillable
First, you'd have to fail the Wisdom saving throw, which RAW you can't just choose to do. If you manage to fail the save, barring the spell being dispelled. You are almost unkillable from anything that tries to pass through the cage.
The target shrinks to a height of 1 inch and is imprisoned inside a gemstone or similar object. Light can pass through the gemstone normally (allowing the target to see out and other creatures to see in), but nothing else can pass through, even by means of teleportation or planar travel. The gemstone can’t be cut or broken while the spell remains in effect.
Sacred Flame From Inside
Jeremy Crawford ruled that Sacred Flame doesn't require a clear path to the target on Dragon Talk from 1/19/17 at 36:20. Not because of the line of sight, but because it states in the spell that it ignores cover. So, by an official ruling, you could be Sacred Flamed from inside the gemstone.
Even with the ruling, I'm not convinced many DMs would allow sacred flame to be cast through the gemstone. The specifics of the spell imply an intent that magic of any kind can't pass through the prison. So, I'm not sure if it would still rain fire from heaven.
Loophole Works Both Ways
If your DM does allow you to sacred flame from inside, then they should allow the spell both ways. Moreover, any spell that allows you to ignore cover would also be allowed to pass into the gemstone using the same loophole you're attempting to use. Moreover, a DM might rule that you are restrained by the spell, which would mean:
- A restrained creature’s speed becomes 0, and it can’t benefit from any bonus to its speed.
- Attack rolls against the creature have advantage, and the creature’s Attack rolls have disadvantage.
- The creature has disadvantage on Dexterity saving throws.
Which would also mean you'd be unable to dodge very well.
Levitate
I think the RAW might allow you to levitate the Gem, but I'm not sure most DM would let make the Gem levitate, either.
Achilles Heal
The plan comes with one quick easy foil:
- throw a blanket over the gem, no more sacred flame
A creature you can see
- simply bat the floating gem... which would then begin floating away
and not cause any problems. Levitate isn't flight, you'd be hit out of the fight like a baseball, with no means to stop or turn around.
The target can move only by pushing or pulling against a fixed object or surface within reach (such as a wall or a ceiling)
No risk of death, but you're out of the fight until you get dispelled.
Best Answer
Yes it can.
There's nothing in the rules, or either spell, which says that the material component used for one of these spells can't also be used for the other. The gem isn't consumed by either spell, and as long as the gem meets the requirements for both spells in value and size, you should be able to use it for both.
However, note this wording:
This implies that your soul cannot travel into and out of the gem while Imprisonment is in effect. So if your soul is still in the gem, you can't possess a creature until Imprisonment ends. Likewise if you have possessed a creature, your soul cannot return to the gem until Imprisonment ends.
Fortunately, Imprisonment allows you to set a condition for ending the spell:
So you could set the condition that Imprisonment ends, for example, when the body you're possessing through Magic Jar dies. Work with your DM to get the condition exactly right for your purposes.