What Gandhi realized early on was that the people of the British Empire were basically civilized and wanted to think of themselves as good people. The British had put in place a system of laws that made Indians in their own homeland into second class citizens. These laws were designed to preserve Indian dependence on Britain. In effect, law was being used to legitimize British oppression of Indians, and as a lawyer, Gandhi could see this, clearly. He also understood that it was easy for the British people to put this oppression out of their minds as long as Indians avoided confrontations with the legal system.
Gandhi's strategy was to look for the most absurd legal tools of British oppression that he could find and to use them to confront the British with their oppression by making a public spectacle of his defiance of the worst of these laws. Gandhi knew that the British were basically good people who were, on the whole, deceiving themselves about their role in India. He knew that if they really had to face up to what they were doing in India, they would loose their will to retain power there. When Gandhi marched to the sea and unlawfully picked up an handful of salt from the beach, he was publicly daring the British government to show the British people just how brutal they could be over something so silly as a law criminalizing the manufacture of salt by Indians in India. He was certain that the people in Britain, if they understood what was happening in India, would be forced by their conscience to give up power in India.
When we look at Gandhi's strategy this way, it is obvious that the Indians should not respond with violence. Any attempt by Indians to respond violently to their oppressors could easily be distorted into an excuse for the British to exert more power. There were British government officials in power in India who would have willingly distorted the facts to justify the power that they held. Gandhi's strategy was to appeal to the people of Britain, and for that appeal to work, Gandhi could not give anyone room to argue that the Indians were the source of their own problems and were too uncivilized to rule themselves. While Gandhi was confident that the British people and would do the right thing if they understood the truth, he also knew they were already trying avoid that truth and could easily be swayed to continue to avoid it if the Indians could be portrayed as barbaric.
All this is not to say that Gandhi only avoided violence for this pragmatic purpose. I believe nonviolence had an appeal of its own for Gandhi, as it must for all good people. I think there were already many important elements in Indian culture that prepared them to resist the impulse to respond to injustice with violence, once Gandhi urged them to resist that impulse. But I don't believe Gandhi would have ever endorsed the avoidance of violence at all costs under all circumstances.
Gandhi's strategy showed uncommon brilliance and extraordinary insight into the character of his oppressors. If the British had not been the good people that Gandhi thought they were, his strategy could never had worked. To characterize his strategy simply as one of "nonviolence" misses the entire point of what he accomplished and creates a kind of caricature of the man and of his accomplishments. While all good people should look for nonviolent solutions to problems over violent solutions, this laudable goal should not tempt us to characterize a brilliant strategy that included nonviolence as a simple minded strategy that simply was nonviolence.