If the target creature is an illegal target by the time Niambi's triggered ability tries to resolve, the ability won't resolve. You won't return the card from the zone it moved to or gain any life.

Artwork
Loading artwork…
Niambi, Esteemed Speaker
Core Set 2021 · #222 · EN
Nonfoil—Foil—
Card rules
Flash
When Niambi enters, you may return another target creature you control to its owner's hand. If you do, you gain life equal to that creature's mana value.
1
,
, Discard a legendary card: Draw two cards.
2/1
Rare · Illustrated by Eric Deschamps
Format legality
Brawl Legal
Commander Legal
Competitive Brawl Legal
Duel Legal
Gladiator Legal
Historic Legal
Legacy Legal
Modern Legal
Oathbreaker Legal
Penny Legal
Pioneer Legal
Timeless Legal
Tlr Legal
Vintage Legal
Alchemy Not Legal
Future Not Legal
Old School Not Legal
Pauper Not Legal
Pauper Commander Not Legal
PreDH Not Legal
Premodern Not Legal
Standard Not Legal
Standard Brawl Not Legal
Rulings
Published rulings from the downloaded Scryfall catalog. Source card record · Rules and interactions
If a creature on the battlefield has X in its mana cost, X is considered to be 0.