It wasn’t. The British were prepared to, and did, kill non-violent protesters, most notably at Jallianwala Bagh, where nearly 400 people (the official figure: other sources place it much higher) were shot dead in 10 minutes.
Britain left because, as @enkita pointed out, it was financially exhausted after six years of war, and because the population had made it plain they wanted the British out and would use violence to kick them out if necessary.
Check out the Quit India movement of 1942: dozens of bombings, thousands of people killed, 70 police stations destroyed, and 57 battalions deployed to restore order. Parts of Uttar Pradesh passed out of British control for weeks, and parallel governments in areas of Midnapore continued to function until 1944.
Then there was the Indian National Army, who took up arms against the British in alliance with the Japanese (many were recruited in Japanese PoW camps). In military terms they may have had little significance, but they captured the popular imagination, and the British attempts to try some of them for treason after the war had to be abandoned in the face of outcry from a public that regarded them as patriotic heroes. There’s a monument to them in Singapore (or at least there was 20 years ago).
Gandhi wasn’t a pacifist. He believed that non-violent resistance was practically and (more importantly to him) morally superior to violent resistance, but he realised that not everyone was capable of it, much as he might wish otherwise: those who could not resist non-violently had not only the option but the duty to resist violently. If you were not prepared to die, you had to be prepared to kill.
