[Note of Caution: I am not a professional historian but i happened to do a course on Indian Constitution and a handful of courses on Modern India in college]
After India became independent from the British, there was discussions as to what India's political system would be. For the risk of oversimplifying, Mahatma Gandhi and Jawaharlal Nehru were by far the most influential politicians in India. Gandhi would roughly correspond to being a "Libertarian Socialist" with some "Indian characteristics". He wanted both decentralisation of power and collective ownership of resources. But on the other hand, Nehru was a Fabian Socialist (the ideology followed by the Labour Party in the 20th Century) in every sense of the word. While he admired the Soviet Union, he was not a fan of Communism because of its authoritarian tendencies. So he wanted a system which combined collective ownership and centralisation with a strong democracy. Since Gandhi died before the Constitution was framed, Nehru had his way when India's political system was designed.
India was very much a socialist country till 1991 (possibly ever after in some ways, depends on who you ask) but with a strong democratic oversight over the government. India started implementing Five-Year Plans even before Maoist China, tried emulating Stalin Ist Russia through Top-Down Heavy-Goods Industrialization with a strong dash of License-Permit-Quota soup (the "License Raj", as it is affectionately called). This was followed by waves of Nationalisation in a wide swath of industries. These processes continued long after Nehru's death in 1964 (it can even be argued that India became more Socialist after Nehru died).
But the Constitution never proclaimed that India was Socialist until the dark days of the Emergency in 1976 (when political opposition was repressed) when the government of Indira Gandhi (daughter of Nehru) pushed through the 42nd Amendment which proclaimed India to be both Socialist and Secular. But of course this was a semantic change as India's political system was de facto Secular and Socialist long before the Emergency.
Skipping over to 1991 when India started to do away with most of the "License Raj" institutions in favour for a more liberal system. Unlike in China, these reforms were brought during a financial crisis by a government that didn't command majority support of the parliament, and decades of Socialist rhetoric made liberal reforms really unpopular then. It must also be noted that the Congress (Nehru's party) was ruling India then and they still banked heavily on the legacy of Nehru and his descendants for their survival so they didn't want to turn on their past. Due to these reasons, then Prime Minister PV Narasimha Rao chose to market these reforms as a logical extension of Nehruvian Socialism and not a turning back on 40 years of Socialism (this, of course is paralleled by Deng's Socialism with Chinese Characteristics) which meant that India continued to make liberal reforms while still identifying as a Socialist nation.
It is also curious to note that almost all of the major parties in India (from the Communists to the BJP) mentions achieving Socialism as one of their aims in their manifestos. Part of this is a legacy of Gandhian ideals (which increasingly became conflated with Socialism from the 1950s on) and part of this is due to the aversion of the Indian public to a more "Capitalistic" rhetoric which makes attempting liberal reforms while claiming to be Socialist a rational course of action in India.
[Edit: Changed 39th Amendment to 42nd Amendment, Changed Financial Emergency to Financial Crisis to not confuse it with a Constitutional Provision of the same name]
References:
India After Gandhi- Ramachandra Guha
India Unbound- Gurcharan Das
To The Brink and Back: India's 1991 Story- Jairam Ramesh
India's Founding Moment- Madhav Khosla
Manifestos of Indian National Congress, Bharatiya Janatha Party and Communist Party of India (Marxist)
To add to the succint answer by /u/wethemuggle it would be helpful to add another important context in which the issue of socialism came up, that of private property. This is only a very brief introduction to the same. In keeping with the ideas of liberal constituionalism , the right to private property was enshrined under Art.19(1)(f) of the Constitution, however this sat rather uncomfrotably with one of the key aspects of the post-independence program of land reform and the abolition of the Zamindari (landlordism) which took various forms across the country. This is tied in with core socialist concerns regarding more equitable forms of wealth distribution, also additionally there was often the element of caste as well which tied into patterns of local land ownership, which made land reform a rather pressing concern for the new government. This clash between the right to property and the land reform program set the stage for a series of clashes between the legislature and judiciary over the constituionality of land reform legislation, which in turn prompted repeated amendments to property rights in the constitution and the ultimate decision to remove the right to property as a fundamental right. This clash reached a peak under Indira Gandhi who especially in the run-up to the 1971 elections wanted to differentiate herself from the old guard of the Congress party represented by the Organisation (O) faction and pushed for more avowedly socialist policies under the slogan of 'Garibi Hatao' (Remove Poverty). This gave her a thumping majority in the elections though it also prompted her to take on a more authoritarian slant in the running of the government, culiminating with the delcration of the Emergency in 1975. In response to all these changes, the Supreme Court by a narrow majority formulated the doctrine of basic structure in the case of Kesavananda Bharati v. State of Kerala (1973 SC) to counter such future amendments by legislature if they went against the basic ideas of the constitution as formulated by the founding members of the constituent assembly, with this still being the law of the land. It should be noted that the amendments to the constitution inserting the word socialist in the preamble (42nd amendment 1976) and abolishing the fundamental right to private property (44th amendment 1978) all occured after the formulation of the basic structure doctrine in the Emergency and the post-Emergency context respectively.
Sources: Namita Wahi, The Constituent Assembly Debates on Property: Unravelling the Property Paradox, Centre for Policy Research 2021
Gopal Sankaranarayanan, The Fading Right to Property in India, Law and Politics in Africa, Asia and Latin America 2011
Shruti Rajagopalan, Incompatible Institutions: Socialism versus Constitutionalism in India, Constitutional Political Economy 2015
Adding to the excellent answers in here, but again from the lens of political science, it might be useful to keep in mind the support for state led industrialization as a model of development for the new Indian state. Nayar(1997) argues that the choice of state ownership of the "commanding heights" of the economy follows from Nehru's commitment to a Fabian socialism as opposed to either the economic Zeitgeist or building capitalism which I find convincing.
In addition to Nehru's personal ideology, in the early years of the republic there was a substantial socialist movement, one that had to be placated by "expressive accomodation" (Khaitan, ) through the addition of socialistic principles in the DPSP. This was used by Indira Gandhi in her leftward movie for CPI support in her fight with the INC(O)
References
NAYAR, B. R. (1997). Nationalist Planning for Autarky and State Hegemony : Development Strategy Under Nehru. Indian Economic Review, 32(1), 13–38. http://www.jstor.org/stable/24010467
Khaitan, Tarunabh, Directive Principles and the Expressive
Accommodation of Ideological Dissenters (2016). 16(2)
International Journal of Constitutional Law 389, U of Melbourne
Legal Studies Research Paper No. 790, Oxford Legal Studies Research Available at SSRN: https://ssrn.com/abstract=2888987 or http://dx.doi.org/10.2139/ssrn.2888987
To add to the some of the excellent answers here, I think it might be examine to examine snapshots of authoritarianism in the pre-Nehruvian, Nehruvian and post-Nehruvian eras of Indian leadership.
One thing to keep in mind is that the Indian National Congress, the leading body in India's independence struggle, was largely a decentralised movement borne out of local-level politics and advocacy.
In keeping with these more ground-level roots, the rank-and-file of the Congress was diverse but decidedly with a conservative hindu slant. This differed quite starkly from the Congress' leadership at the top level which tended to be dominated by liberal constitutional scholars like MA Jinnah(who would go on to found an ultimately illiberal neighbouring state) and firebrand leftists like SC Bose.
Subhash Chandra Bose most clearly embodies an alternative direction that India could have taken. He clearly articulated a more authoritarian vision of an unpartitioned, secular and militaristic state. Like Jinnah, however, Bose was also sidelined by Gandhi's emergence onto the national stage in favour of his own disciples, Nehru and Patel.
SC Bose would ultimately spend the second world war petitioning the USSR and Nazi Germany for support in a bid to fight for India's independence. Ultimately, he did find backing from Imperial Japan and led an army of Indian prisoners-of-war against the British Raj.
Despite remaining a popular figure in India, Bose died in a plane crash before the cessation of hostilities in WW2, and so was not able to play a role in the polity or independent India.