All the other princely states got integrated into either India or Pakistan. Why was Kashmir left independent?
[1/2]
So there's a simple and a more complicated answer to this. Let's start with the easier one, going back to
the princely states & Kashmir
The princely states had a special status in comparison with other parts of the British Raj – they had not been directly conquered or integrated in other ways (e.g. with the British taking over after the death of a ruler). Because of this, the « transfer of power » of the British with partition by law only affected British India. Each one of the princely states had become independent « on their own » so to speak, after Great Britain declared that the British Crown's rule over them would end with Indian indepependence for them as well. The judicial autonomy of the princely states had always been highlighted by the British, e.g. meaning that the Viceroy was only the Crown's representant vis-à-vis the princes without other rights.
These Indian rulers all had their own contracts with the Crown, because they had at some point laid down the weapons and surrendered, leading to a high degree of autonomy and « indirect » British rule. These states were often those where spendings on protection and administration would have been higher than their economic rentability had the British decided to take over. Because of their special status, the rulers of Jammu & Kashmir, Hyderabad and Mysore and Jaipur feld privileged in comparison to the « lower » rulers of other states. What is more, democratisation was pretty much lacking in comparison to British India withouth its administrative reforms. However, after the 2nd World War there was a « bad awakening » for these rulers – without British protection they could not hope to retain their autonomy. So, many of these rulers tried to salvage some rights and privileges by cooperating with the British just prior to partition.
Moving on towards partition, we now have the special situation of the princely states being told by the British that they could choose to either accede to India or to Pakistan. For most this was not that complicated – the large majority of them went over to India, as often they were already inside of the newly Indian territory, with a few joining Pakistan where this made more sense because of religion and/or territorial proximity (Makran, Kharan, Las Bela). This whole process was overall rather peaceful, with some exceptions : Jammu and Kashmir, Hyderabad, as well Junagadh (ruler acceding to Pakistan, then annexation by India) and Kalat (ruler declared independence, then annexed by Pakistan) – note that at this point still Kashmir was not the only state that was not integrated, which would change by 1948.
The first two states mentioned above were the largest and most important of those exceptions. With Hyderabad there was a Muslim ruler over a Hindu majority population which created frictions – the ruler announced independece in '47 only to be annexed by India the following year. With Jammu and Kashmir it was the reverse case of a Hindu ruler (and upper class) having ruled for ca. a century over a mostly Muslim and relatively poor population. This once more meant political friction between the ruler and Muslim political parties since the early 1940's at least, and together with other influences led to the ruler Hari Singh having difficulties in deciding where to accede. It was expected he would accede to Pakistan but he hesitated. So Pakistan
launched a guerrilla onslaught meant to frighten its ruler into submission. Instead the Maharaja [Singh] appealed to [the Viceroy] Mountbatten for assistance, and the governor-general agreed on the condition that the ruler accede to India. Indian soldiers entered Kashmir and drove the Pakistani-sponsored irregulars from all but a small section of the state. The United Nations was then invited to mediate the quarrel. The UN mission insisted that the opinion of Kashmiris must be ascertained, while India insisted that no referendum could occur until all of the state had been cleared of irregulars. (Burton Stein, History of India)
This in the end led to a ceasefire and to the Karachi accord of '49 but no official border was drawn – as the referendum demanded by the UN was never accomplished due the continuing simmering (and sometimes overblowing) conflict between India and Pakistan over Kashmir and other topics/regions. This map is very general, but at least shows a bit the annexation of the two states, Hyderabad and Kashmir. This one shows the eventual division of Kashmir with the Line of Control, which is still in place today instead of an official border.