According to the Devi Bhagavata Purana, Brahmavaivarta Purana, and Shiva Purana, shilagrama shilas originated due to the following chain of events.
A king named Vrishadhvaja had been cursed by Surya to endure poverty, due to his reluctance to worship any deity other than Shiva. To regain their lost prosperity, his grandsons Dharmadhvaja and Kushadhvaja performed austerities to appease Lakshmi, the goddess of prosperity. Pleased with the austerities, she granted them prosperity and blessed them by being born as their respective daughters, Tulasi and Vedavati. Tulasi went to Badarikashrama to perform austerities as she desired Vishnu as her husband, but was told by Brahma that she would not get Vishnu as her husband in that life, and would have to marry the danava (demon) Shankhachuda.
In his previous birth, Shankhachuda was Shridhama, a supreme devotee of Krishna, an incarnation of Vishnu. In Goloka, he got the instructions from Krishna himself, to be born as a danava. As a result, Shankhachuda was virtuous and pious by nature, and was devoted to Vishnu. On the command of Brahma, he and Tulasi had a Gandharva marriage. Afterwards, the danavas, under Shankhachuda's leadership, waged a battle against their natural enemies, the devas, in which they won due to merit of Shankhachuda's virtue. The devas were subsequently driven out of Svarga by the victorious danavas.
Demoralised and defeated, the devas approached Vishnu, who told them that Shankhachuda was destined to be killed by Shiva. On being requested by the devas, Shiva, along with his attendants and the devas, waged a battle against the danavas, led by Shankhachuda. However, neither side was able to overpower the other. An unembodied voice told Shiva that by the boon of Brahma, Shankhachuda was invincible in combat as long as he wore his armour, and his wife remained a virgin.
Vishnu, assuming the form of an old Brahmin, asked Shankhachuda for his armour while begging alms. Shankhachuda donated his armour to him. When he was busy fighting with Shiva, Vishnu, wearing Shankhachuda's armour, assumed the form of Shankhachuda, and lay with Tulasi. Thus, Tulasi lost her virginity, and Shankhachuda was killed by Shiva's trishula, thereby relieving Shridama from the curse.
At the moment of Shankhachuda's death, Tulasi became suspicious that the man with her was not Shankhachuda. When she discovered that it was Vishnu had deceived her, she cursed him to become a stone, as she believed that he had been emotionless like a stone in accomplishing the death of his devotee, Shankhachuda, and taking her virginity, though she was also his devotee. Vishnu consoled Tulasi by clarifying that it was the result of her austerities performed in the past in order to gain him as her husband, and that she would again become his wife upon casting off her body. Thus, Lakshmi cast off the body of Tulasi, and assumed a new form (which became known by the name of Tulasi). The discarded body of Tulasi was transformed into the Gandaki River, and from her hair emerged the tulsi shrub. Vishnu, on being cursed by Tulasi, assumed the form of a large rocky mountain known as shaligrama, on the banks of the Gandaki River where vajrakita, a type of worm with teeth as strong as the vajra, carved out various markings on his body. Such stones which fall from the surface of that mountain into the Gandaki River came to be known as the shaligrama shilas.