To your knowledge all states were independent at that time and given right to become independent and to be part of India and ruler of kashmir decided to go with india.
Pakistan even tried to capture the kasmir state forcefully at that time but failed.
Due to a opportunist Nehru, 'Gaddar Muslim kaum' and pakistan we are facing this problem.