The story of Shandili and Kaushik is given in Garuda Purana.
Once on a time there lived in the city of Pratisthana, a leper Brahmana whose name was Kaushika. His wife, who was firmly devoted to
him, used to adore and worship her lord as a god without even thinking
for a moment that he was afflicted with such a foul and loathsome
disease. But Kaushika was a cross and peevish husband, and never
missed opportunities to abuse his wife, who, though often chastised,
never ceased to pay him god-like veneration and love. One day,
Kaushika took a fancy to visit a courtezan in the city, and expressed
that desire to his wife. Whereupon she took him on her shoulders and
safely carried him to that house of ill fame. Nor did she forget to
take with her a considerable amount of money which the courtezan might
ask for her nefarious trade.
Now it happened that the Sage Mandavya was then undergoing punishment
on the top of a pointed mace, as he was unjustly sentenced by the
authorities on a false charge of theft. The faithful wife, on her way
to the house of the courtezan, touched with her feet the body of that
afflicted sage, who, in his agony, cursed her with the pangs of
widowhood on the break of day. The wife, on the other hand, forbade
the Sun to rise in order that the curse of the Sage might not take
effect. The Sun-God, overpowered by the energy of conjugal chastity,
was afraid to show his face, and creation was enshrouded in a pall of
darkness. Ages past without the Sun in the sky.
The frightened gods resorted to Brahma for help and advice. Brahma
“It is the energy of Chastity that has overpowed the energy of
asceticism, and obstructed the advent of the Sun. Go, ye gods, to
Anasuya, and she will plead, on your behalf, to the wife of Kaushika.”
The gods did as they were told to do. Anasuya saw and propitiated her
with the boon of a long life and perfect health to her lord, and lo
and behold, the Sun-God again appeared in the sky.