There is a sutta where the Buddha teaches some disciples about loathsomeness of the body. He then goes on a retreat into the forest. On his return, he finds the disciples have committed suicide as they have grasped the teachings incorrectly. The Buddha than proceeded to teach Anapana Sati as it is much safer. Does this prove that even the Buddha was capable of making mistakes? In hindsight, should he have used the ability of omniscience to anticipate the result of his instructions. Or, was this event unavoidable fruition of the disciples' past Kamma.
You have misunderstood the sutta SN 54.9.
The Buddha taught the technique of loathsomeness of the body, which is to be used to remove feelings of sexual lust and attachment to the physical form. This technique is useful to be practised by a monk or practitioner who is overwhelmed by sexual lust. However, too much of this practice, especially when it is unnecessary, may lead to depression and suicidal tendencies.
To counteract depression and suicidal tendencies, the Buddha prescribed mindfulness of breathing, which can generate rapture and joy.
So, as you can see, every technique has a different purpose. Any one single technique does not fit everyone at all times. Sometimes, you have to change your technique depending on the circumstances.
For example, a person who is momentarily overcome by one of the five hindrances would have to try some technique to overcome that particular hindrance.
Hence, the Buddha did not make a mistake in this case. He merely prescribed different techniques for different conditions. Please also see this answer.
The Buddha will not make mistakes when it comes to the teachings and practice of Buddhism.
Although the Buddha was known to have some psychic powers, he was not completely omniscient (i.e. knowing all things in the past, present and future), in the way people consider a Supreme God to be. Buddhist enlightenment is about freedom from suffering. It's not about becoming God-like.
Or, was this event unavoidable fruition of the disciples' past Kamma.
The Commentary seems to say it's due to past kamma. From Ven. Bodhi's note citing the Comy.'s explanation to the strange case of SN 54.9:
Spk: Why did he speak thus? In the past, it is said, five hundred men earned their living together as hunters. They were reborn in hell, but later, through some good kamma, they took rebirth as human beings and went forth as monks under the Blessed One. However, a portion of their original bad kamma had gained the opportunity to ripen during this fortnight and was due to bring on their deaths both by suicide and homicide. The Blessed One foresaw this and realized he could do nothing about it. Among those monks, some were worldlings, some stream-enterers, some once-returners, some nonreturners, some arahants. The arahants would not take rebirth, the other noble disciples were bound for a happy rebirth, but the worldlings were of uncertain destiny. The Buddha spoke of foulness to remove their attachment to the body so that they would lose their fear of death and could thus be reborn in heaven. Therefore he spoke on foulness in order to help them, not with the intention of extolling death. Realizing he could not turn back the course of events, he went into seclusion to avoid being present when destiny took its toll.