Why did Shikamaru Marry Temari

How can Temari live with Shikamaru?

While the sand village and the leaf village were in different nations, shinobi can leave and leave different villages as long as they do not give up their duties in their previous village. Otherwise, they would be considered missing-nin

After the Second Great Ninja War, Tsunade withdrew from the shinobi life and left Konoha.

Leaving the village doesn't necessarily make you a missing nin. Tsunade retires from life as a ninja and leaves Konoha after the Second Shinobi World War

Temari and Shikamaru are not the first time we see shinobi marriages from different villages. Naruto's mother Kushina was originally from Uzushiogakure (land hidden in the swirling tides)

Kushina Uzumaki was a Konohagakure Kunoichi who came from the Uzumaki clan of Uzushiogakure

...

Kushina was born into the famous Uzumaki clan of Uzushiogakure and spent most of her youth at war, seeking daily peace. At a young age she was sent to Konoha and enrolled in the academy

However, Uzushiogakure also belonged to the land of fire, it was about different villages.

We have, too seen other cases of shinobi immigrating to other nations. An example is when Jiraiya Rasengan first played against some gansters

The boss used to be a Ch┼źnin from the hidden village of the stone

The hidden village of the stone is in the land of the earth