Masterful Ninja's first activated ability doesn't cause any enters-the-battlefield abilities to trigger. When the turn ends and Masterful Ninja stops being both on the battlefield and in your hand, this won't cause any dies or leaves-the-battlefield abilities to trigger. If Masterful Ninja enters or leaves the battlefield some other way, those abilities work as normal.