Lord Shiva was a vairagi in the starting, then why did he turn into a grihastha by marrying Goddess Sati and then her reincarnation Goddess Parvati?
Lord Shiva (Rudra) was married from the beginning. Puranas like Bhagavatam, Vishnu Puran, etc. give the account how Rudra was born from Brahma and married Sati, the daughter of Daksha, as his wife. Below is a description from Vishnu Purana:
Later on Brahma commenced the process of creation. During that time he desired a child like himself. Then a blue-red colored child appeared on his lap and started crying as he wanted a name. Brahma named him Rudra, but he still continued to cry. So Brahma gave him another seven names. They are: Bhava, Sarva, Ishana, Pashupati, Bhima, Ugra and Mahadeva. Rudra married to Sati, the daughter of Daksha. Sati getting angry on Daksha gave up her life and reborn as Parvati, the daughter of Himavat and Mena. Then Hara (Shiva) again married Parvati. [VP - 1.8.2-14]
But after casting of the body by Sati, Lord Shiva resumed His ascetic form. However, the demon Tarakasura had the boon that he would only be killed by Siva's son. May be he thought Siva was an ascetic and won't marry and hence won't have a son. But the gods requested Himavat to accept Parvati as his daughter and then suggested Kamadeva to afflict Shiva with desire for marriage. But Shiva burned Kama to ashes. Then the gods pleaded Shiva to marry Parvati and begot a son so that Tarakasura can be killed. So Lord Shiva told them:
nocita hi vidhānaṃ vai vivāhakaraṇaṃ nṛṇām
mahānigaḍasaṃjño hi vivaha druḍhabandhanaḥ
kusaṃgā bahavo loke strisaṃgastatra cādhikaḥ
uddharetsakalebaindhairna strisamgātpramucyate [Shiva Pu. - 2.24.60,61]
As far as possible, man should not marry. Marriage known as chain is a very strong bondage. Usually there are many kusanga (bad association) in the world, but association with women is the worst of all. One can free himself from other bad associations, but cannot free himself from a woman.
But because Lord Shiva is fond of and saviour of devotees, instead of His unwillingness, He agreed to the gods' proposal and became a grihasta (family man):
ayathocitakartā hi prasiddhau bhubanatraye
nāsti yadyāpi me kaścidihakaraṇe ruciḥ
vivahayiṣye girijāṃ putrotpādanahetave [Sv. Pu. -2.24.67,75]
As I am under my devotees, I do all their work. Even I am famous in all the three worlds as someone who gets the odd jobs done. So even though I have no desire and liking in these things, I will marry Parvati for the purpose of begetting a son.
The Mahabharat has a different version of the story where the gods stop Shiva from begotting a son as it would be fierce enough to devour entire world. So Shiva draws up his semen and hence called as Urdhareta (one who has taken his semen up) since that day. Generally the yogu ascetics are known as urdharetas.
Here is how it happened. Nothingness (ShivA) -> Vishnu -> Brahma -> Shankara (Sakaar roop of Lord ShivA). It is foolish to say Lord Shiva is the son of Brahma Dev. Just as Lord Ram is born from Kaushalya, similarly Lord Shiva took birth in this material world through Brahma. Lord Shiva's nirakaar nirgun roop is unborn, but his Physical Sakaar roop is born or took place.
Shiva = Shiv + Adi Shakti (Material/Prakriti). When Shiva separated him from Adi Shakti, nothing was left, no material possesion hence only thing left was Vairag.
Shiv did not want to marry. He was totally against marriage and love but then one day a demon named Tarkasur asked him for a boon that only Shiv's son can kill him. Shiv did not have a choice but give him the boon. Tarkasur knew that he couldn't ask for amrit. So, he took boon from Shiva as he was a vairagi and couldn't marry and get a child. But then, what has born has to die. So sati was born. Shiva did not want to fall in love with her but couldn't help it. His love is pure towards her.But destiny lied somewhere else and sati decided to die.( why did she is another story). Shiv cried like anything over her death as he loved her. Nobody could separate sati from shiv. So she took another birth to meet her love once again. She was Parvati now. And once again Shiv and shakti were together. Then Kartikeya was born and he killed Tarkasur