they were the same people a lot of the time, people think of samurai like these super honorable lawful almost religious guys but that was made up after samurai were irrelevant (kinda like europeans and knights), back in the day, if you weren't willing to cheat, lie, steal, murder, etc. for your Daimyo, you weren't really loyal at all - many 'ninja' were simply samurai or their men concealing their identity, or were otherwise specialist mercenaries hired by samurai/feudal lords in secret. in some eras and places Samurai would even test new blades by hiding near a road and sneaking up and killing peasants at night, a good sword was supposed to kill in 1 clean cut - sounds very much like Ninja behavior to me.
they were basically the same as european knights, bloodthirsty warlords working for the local barons, and they would absolutely use stealth or subterfuge to accomplish their lord's will, because they were more or less intelligent rational people trying to accomplish material goals, not cartoon zealot idealists obsessed with 'honor' and 'purity' - the only 'honor' is serving your lord, the only 'purity' is in unwavering loyalty.