After WWII, it was a given Indian would be independent. What you have to understand is the British ruled India by two ways, first was the British Raj, and the second was by the sworn allegiance of literally thousands of tiny independent princely states.
The Muslims declared they could never get a fair shake in Hindu India, a theory that has been disproven. Muslims form a much stronger middle class in India, indeed the three richest Indians are Muslim.
The princely states could in theory choose to be independent, go to Pakistan or India. In reality, those in the West had to choose Pakistand and independence was not an option. For instance, the State of Hyderabad was ruled by a Muslim prince, but had an overwhelmingly majority Hindu population. The prince wanted Pakistan or Independence. But since Hyderabad is right in the middle of southern India, it would be illogical to allow it independence or to be with Pakistan.
In some areas like the Punjab you had Muslims, Sikhs and Hindu, all thoroughly intermixed. So relocation of populations was to be a given.
In the East they divided Bengal into East Bengal and West Bengal. East Bengal mostly Muslim became East Pakistan. East Pakistan had more than 51% of the total population of Pakistan, the theory was the religion would unite the Bengalis with the other Muslims in the west. This never even came close to happening.
In the North Kashmir was ruled by an Indian prince but with a Muslim majority. The prince wanted independence, but neither India nor Pakistan would allow it. When the Pakistanis invaded to enforce the claim, the Hindu prince signed on to India for protection.
The Chittagong Hills in what is now Bangladesh was 97% non-Muslim (mostly Buddhist) but given to East Pakistan.
So you can see it wasn't as easy at it looks to divide India into neat packages. Indeed for the next ten years after independence, India was reorganizing it's states, combining some, eliminating others.