From the Super Mario Wiki
The Invincibility Egg is an item found only in Yoshi's Woolly World. The item will appear once Yoshi has been defeated five times, much like the Invincibility Leaf. The major difference, however, is that there is no negative effect on game completion if Yoshi uses the Egg.
Like the name of the item implies, it grants Yoshi invincibility to damage by enemies, signified by Yoshi glowing multiple colors. However, no knockback resistance is given (Yoshi can still be pushed around by enemies and their attacks without being harmed), and unlike most cases of invincibility, Yoshi cannot defeat foes instantly by merely touching them. There is also no immunity to damage caused by spikes, lava, being crushed, touching Naval Piranha in World 4-S, and bottomless pits with the Egg's power, but with certain Power Badges, Yoshi can combine the Egg's power with either immunity to fire and lava or bottomless pits.