I have noticed that multiple non-socialist countries reference socialism in their constitution including Portugal, India and Sri Lanka. Why is this?
Propably because a sufficiently large power bloc within these countries was pushing for socialism at the time of creation of their constitutions. Portugal, for example, was prevented from declaring a Peoples Republic by NATO outright sending warships to the capital during their revolution.
Reactionaries then took over in these states
Socialism in popular consciousness is not always seen as the transitory phase towards communism. Sometimes it is conflated with the existence of a welfare state of some variety. I.e. when the government does stuff.
The socialism in Indian constitution comes mainly from how Nehru and his peers understood it. He was educated in England and hung out with utopian Fabian socialists.