Ninjas were useful because they could do things that violated Bushido. However, they did have their own moral code.
In the translation of the Bansenshukai (one of the manuals used by ninjas), there is entire portion devoted to "Correct Mind". The Bansenshukai is translated by Antony Cummins and expresses that ninjas should be able to stray from a righteous path as long as their motivations are not for self-gain, but to serve a uncorrupt employer.
Along with this, the chapter "Correct Mind" talks about many other philosophies used by the ninja. For example, the handbook encourages courage, but not the kind that leads to making reckless decisions or following irrational leaders. So in a way, the ninja did have a moral code, but not a traditional kind.
There were a set of guidelines that allowed them to perform morally questionable actions, without becoming reckless or motivated by self-gain. There were provisions in the manual to prevent them from being manipulated, but allowed them to manipulate others.
The difference between Bushido and ninja codes is that Bushido was meant to preserve honor and ninja philosophy was structured to keep the ninjas on a path were they could avoid falling victim to greed, blind allegiance or anything that would make them less effective in their profession.
Source: The Book of the Ninja by Antony Cummins