Ariyapariyesana Sutta: The Noble Search (MN 26):
'Lord, let the Blessed One teach the Dhamma! Let the One-Well-Gone teach the Dhamma! There are beings with little dust in their eyes who are falling away because they do not hear the Dhamma. There will be those who will understand the Dhamma.'
"That is what Brahma Sahampati said. Having said that, he further said this:
'In the past
there appeared among the Magadhans
an impure Dhamma
devised by the stained.
Throw open the door to the Deathless!
Let them hear the Dhamma
realized by the Stainless One!
Just as one standing on a rocky crag
might see people
all around below,
So, O wise
one, with all-around vision,
ascend the palace
fashioned of Dhamma.
Free from sorrow, behold the people
submerged in sorrow,
oppressed by birth & aging.
Rise up, hero, victor in battle!
O Teacher, wander without debt in the world.
Teach the Dhamma, O Blessed One:
There will be those who will understand.'
You ask why he "appeared", I assume that means "became a teacher instead of remaining a recluse", and I suppose this sutta explains that.
It's "for the sake of":
- "beings with little dust in their eyes who are falling away because they do not hear the Dhamma"
- "those who will understand the Dhamma"
So the first criterion seems to be "understanding".
Some (perhaps many) of his followers were initially immoral, famously Angulimala; and of course many had lay lives, were married and so on (not that that's immoral in the same way, but).
Of course the Dhamma teaches morality, and after ordaining they 'must' behave well, but that's afterwards.
In summary I think it was not "to show the 'righteous' (the moral) the way to Nibbana" -- it was "to show the the way to Nibbana, including morality, to those able to benefit/follow".
Also I'm not sure that it was only "to show the the way to Nibbana". You may get that impression for the suttas but he also talked to whole villages when having even only one in the audience become a stream-enterer might be rare. I read a modern commentator say for example that if you can't keep 5 precepts then keeping 4 is better than none. It may be a gradual training -- even a little is good.