Yudhishthira asked the same question to Bhishma as why he was always in favor of the asuras and doing things disagreeable to the dieties.
"Yudhishthira said, 'This curiosity, O sire, is always dwelling in my mind. O grandsire of the Kurus, I desire to hear everything about it from thee. Why was the celestial Rishi, the high-souled Usanas, called also Kavi engaged in doing what was agreeable to the Asuras and disagreeable to the deities? Why was he engaged in diminishing the energy of the deities? Why were the Danavas always engaged in hostilities with the foremost of the deities? Possessed of the splendour of an immortal, for what reason did Usanas obtain the name of Sukra? How also did he acquire such superior excellence? Tell me all about these things. Though possessed of great energy, why does he not succeed in travelling to the centre of the firmament? I desire, O grandsire, to learn everything about all these matters.
Bhishma then told the story about Shukracharya.
"Bhishma said, 'Listen, O king, with attention to all this as it occurred actually. O sinless one, I shall narrate these matters to thee as I have heard and understood them. Of firm vows and honoured by all, Usanas, that descendant of Bhrigu's race, became engaged in doing what was disagreeable to the deities for an adequate cause. 2 The royal Kuvera, the chief of the Yakshas and the Rakshasas, is the lord of the treasury of Indra, that master of the universe. 3 The great ascetic Usanas, crowned with Yoga-success, entered the person of Kuvera, and depriving the lord of treasures of his liberty by means of Yoga, robbed him of all his wealth. 4 Seeing his wealth taken away from him, the lord of treasures became highly displeased. Filled with anxiety, and his wrath also being excited, he went to that foremost of gods, viz., Mahadeva. Kuvera, represented the matter unto Siva of immeasurable energy, that first of gods, fierce and amiable, and possessed of various forms. And he said, 'Usanas, having spiritualised himself by Yoga entered my form and depriving myself of liberty, has taken away all my wealth.
Having by Yoga entered my body he has again left it.' Hearing these words, Maheswara of supreme Yoga-powers became filled with rage. His eyes, O king, became blood-red, and taking up his lance he waited (ready to strike down Usanas). Indeed, having taken up that foremost of weapons, the great god began to say, 'Where is he? Where is he?' Meanwhile, Usanas, having ascertained the purpose of Mahadeva (through Yoga-power) from a distance, waited in silence. Indeed, having ascertained the fact of the wrath of the high-souled Maheswara of superior Yoga-power, the puissant Usanas began to reflect as to whether he should go to Maheswara or fly away or remain where he was. Thinking, with the aid of his severe penances, of the high-souled Mahadeva, Usanas of soul crowned with Yoga-success, placed himself on the point of Mahadeva's lance. The bow-armed Rudra, understanding that Usanas, whose penances had become successful and who had converted himself into the form of pure Knowledge, was staying at the point of his lance (and finding that he was unable to hurl the lance at one who was upon it), bent that weapon with hand. When the fierce-armed and puissant Mahadeva of immeasurable energy had thus bent his lance (into the form of a bow), that weapon came to be called from that time by the name of Pinaka. 1 The lord of Uma, beholding Bhargava thus brought upon the palm of his hand, opened his mouth. The chief of the gods then threw Bhargava into his mouth and swallowed him at once. The puissant and high-souled Usanas of Bhrigu's race, entering the stomach of Maheswara, began to wander there.'
Yudhishthira then questioned his grandfather how Sukracharya succeeded in wandering Shiva's stomach.
"Yudhishthira said, 'How, O king, could Usanas succeed in wandering within the stomach of that foremost of superior intelligence? What also did that illustrious god do while the Brahmana was within his stomach?'
Bhishma then answered.
"Bhishma said, 'In days of yore (having swallowed up Usanas), Mahadeva of severe vows entered the waters and remained there like an immovable stake of wood, O king, for millions of years (engaged in Yoga-meditation). His Yoga penances of the austerest type having been over, he rose from the mighty lake. Then that primeval god of the gods, viz., the eternal Brahman, approached him, and enquired after the progress of his penances and after his welfare. The deity having the bull for his emblem answered, saying, 'My penances have been well-practised.' Of inconceivable soul, possessed of great intelligence, and ever devoted to the religion of truth, Sankara saw that Usanas within his stomach had become greater in consequence of those penances of his. That foremost of Yogins (viz., Usanas), rich with that wealth of penances and the wealth (he had appropriated from Kuvera), shone brightly in the three worlds, endued with great energy.
After that, Shukracharya gets out.
After this, Mahadeva armed with Pinaka, that soul of Yoga, once more betook himself to Yoga-meditation. Usanas, however, filled with anxiety, began to wander within the stomach of the great god. The great ascetic began to hymn the praises of the god from where he was, desirous of finding an outlet for escape. Rudra, however, having stopped all his outlets, prevented him from coming out. The great ascetic Usanas, however, O chastiser of foes, from within Mahadeva's stomach, repeatedly addressed the god, saying, 'Show me thy kindness!' Unto him Mahadeva said, 'Go out through my urethra.' He had stopped up all other outlets of his body. Confined on every side and unable to find out the outlet indicated, the ascetic began to wander hither and thither, burning all the while with Mahadeva's energy. At last he found the outlet and issued through it. In consequence of this fact he came to be called by the name of Sukra, and it is in consequence of that fact he also became unable to attain (in course of his wandering) the central point of the firmament. Beholding him come out of his stomach and shining brightly with energy, Bhava, filled with anger, stood with lance uplifted in his hand. The goddess Uma then interposed and forbade the angry lord of all creatures, viz., her spouse, to slay the Brahmana. And in consequence of Uma's having thus prevented her lord from accomplishing his purpose the ascetic Usanas (from the day) became the son of the goddess.'
Goddess Parvati prevents Shiva from killing him.
"The goddess said, 'This Brahmana no longer deserves to be slain by thee. He has become my son. O god, one who comes out of thy stomach does not deserve slaughter at thy hands.'
"Bhishma continued, 'Pacified by these words of his spouse, Bhava smiled and said repeatedly these words, O king, 'Let this one go whithersoever he likes.' Bowing unto the boon-giving Mahadeva and to also his spouse the goddess Uma, the great ascetic Usanas, endued with superior intelligence, proceeded to the place he chose.