When spectating inside a mob, your name tag is visible on the player preview in the inventory
How to recreate:
While being in spectator mode, enter an entity and open inventory.
The name of the player is being displayed over the model of the player(that is invisible because we're in spectator mode)
For what i've tested, it affects all entities (exept the ender dragon which can't be ridden)
(I didn't include a screenshot because if would show my ingame name)