Kashmir was ruled by Afghan Durran and in 1819 was conquered by the Sikh Empire under Ranjit Sindh. Following the first Anglo-Sikh War (1845-46) Kashmir was ceded under the Treaty of Lahore to the East India Company, which transferred it to Gulab Singh (in 7.5 million nansakhee rupees) through the Treaty of Amritsar. From 1846 till the partition of India, Kashmir was ruled by Maharaj Gulab Singh's Dogra Dynasty as a princely state under British. The British managed defense, foreign affairs and communications and stationed a British Resident in Srinagar to oversee the internal administration.
According to the 1941 census, the state's population was 77% Muslim, 20% Hindu and 3% others (Sikhs and Buddhists). The Muslim majority suffered under the high taxes of the administration and had few opportunities.
After partition, princely states were to choose whether to join India or Pakistan or remain independent. Maharaja Hari Singh choosed 3rd option. When Muslim population demanded to join Pakistan, Maharaja suppressed them with Hindu Dogra troops including members of RSS (Rashtriya Swayamsevak Sangh). Brutal killings of Muslims resulted in rebellion by Muslims of western districts of Jammu and Kashmir against the Maharaja. Pakistan's border Pashtun tribal men entered into Jammu and Kashmir to help the vulnerable Muslims. They soon controlled most of the western parts of the state and formed a provisional Azad Kashmir Government on 24.10.1947.
Being helpless, Maharaja asked India for help, but the government of India required accession to send troops. Accordingly, the Maharaja signed a provisional instrument of accession on 26 Oct 1947, which was accepted by Governor General Lord Mountbatten the next day. Only defense, foreign affairs and communications were ceded to the Government of India, and others to be discussed after the state is cleared of the invaders. While the Government of India accepted the accession, it added the provision that it would be submitted to a reference to the people after law and order prevails. Since only the people, not the Maharaja, could decide where the Kashmiris wanted to live; it was a provision of accession. In the north of the state, Gilgit-Baltistan was joined to Pakistan according to the wishes of its inhabitants.
Moreover, in response to Indian Forces, Pakistan nationals joined Pashtun Tribals for helping the vulnerable Muslims. Being helpless to halt the invasion, the Government of India went to the United Nations.
United Nations Security Council passed its Resolution 47 in April 1948, which resulted in a ceasefire and ceasefire line(LOC-Line of Control in 2-July 1972 Shimla Agreement after 1971 Indo-Pak war) between India and Pakistan. India gained roughly 2/3rd of Jammu and Kashmir (Jammu, Kashmir Valley and Ladakh) and Pakistan gained roughly 1/3rd third of Kashmir (Gilgit-Baltistan and Azad Kashmir).
Moreover, UNSC established a Commission and instructed it to go to the subcontinent to help the Government of India and Pakistan to restore peace and prepare for a plebiscite to decide the fate of Kashmir.
The Commission recommended a three step process:
Pakistan was asked to withdraw all nationals.
India was asked to reduce its forces to a minimum level required for law and order.
India was asked to appoint a plebiscite administrator nominated by the UN, who would conduct a free and impartial plebiscite.
Through Presidential Order 1950, Indian Government gave special status to Jammu and Kashmir under Article-370 of the Indian Constitution, conferring it with the power to have a separate Constitutional Assembly to make a separate Constitution (would define that to what extent the Indian Constitution would apply to the state), a state flag and autonomy over the internal administration of the state. Moreover, The Presidential Order 1954 added Article-35A under Article-370, which empowered the state legislature to define "permanent residents" of the state and provide special rights and privileges like; the ability to sale/purchase land and immovable property; vote and contest elections; government employment; higher education; and health care.
After the Indo-Pak war of 1971, both the Governments signed the Shimla Agreement on 02 July, 1972. According to it, both the countries will "settle their differences by peaceful means through bilateral negotiations".
On 5 August 2019, the Government of India issued a Presidential Order(Jammu and Kashmir Reorganization Bill, 2019), superseding the 1954 order to abolish Article 35A.
Why is the Kashmir dispute not resolved yet?
Lack of unity within the Kashmir resistance: Kashmiri resistance divided between Jammu and Kashmir Liberation Front (JKLF) and Hizbul-Mujahideen, and some others. JKLF wants independence but Hizbul-Mujahideen wants the implementation of UN Resolution of Kashmir and eventual accession to Pakistan.
Indian Intransigence: India is using delaying tactics to implement the UN Resolution regarding plebiscite. Moreover, India wants to change the LOC into an international border. Moreover, India has refused any kind of mediation in the pretext of Shimla Agreement's provision that Kashmir dispute will be resolved through bilateral negotiations. Furthermore, India has labeled the Kashmiri freedom fight as terrorism at international forums.
Unbalanced Pakistan policy: Pakistan hadn't maintained a long-term policy regarding Kashmir dispute. Moreover, Muslilm world has never openly supported Pakistan in this regard. However, the Shimla Agreement has sabotaged the resolution of the Kashmir issue.
Inhospitable International Environment: UNO has shown non seriousness since the first day because of strong trade relations of India with USA and European countries.
Solutions and constraints over them:
Independence: An idea favored by JKLF, but rejected by Hizbul-Mujahideen (dominant group). Moreover, Independence is thought as the third option by India and Pakistan, because India, Pakistan and China believe that an independent Kashmir would set a bad precedent for the balkanization of other restive areas of ethnic minorities in their respective states, and would become the hot bed of Western powers.
Division: India favors the division of Kashmir along the present Line of Control, but this proposal is not acceptable to Kashmiris and Pakistan. Another option is to divide on religious grounds, which seems much better and practicable because Kashmir's population is much polarized on religious grounds.
UN Trusteeship: Some scholars want to put Kashmir under trusteeship of the UN for five or ten years, to arrange a plebiscite. But Past record of the UN is not good in settling issues of third world countries like Iraq, Palestine etc. Moreover, both the countries would not agree on it.
UN Resolution: UNSC's Resolution of April 21, 1948 proposed a package deal comprising three sections; withdrawal of forces, plebiscite and interim government in Kashmir. Both India and Pakistan raised several objections to the plebiscite scheme.