How can Temari live with Shikamaru? Currently, I was watching the "Boruto: Naruto Next generation" series and I saw the scene where Temari and Shikamaru were talking to each other now that they are married. Now, it kind of got me wondering: don't all the village (Hidden Sand, Hidden Leaf, Hidden Mist, etc.) strictly forbid villager from coming out of their village, just so they can keep the village's secret?
While the Sand Village and Leaf Village were in different nations, Shinobi are able leave and go to different villages as long as they do not abandon their duties in their previous village. Otherwise, they would be considered Missing-Nin

After the 2nd Great Ninja War, Tsunade retired from the Shinobi life and left Konoha.


  Leaving the village does not necessarily automatically make one a missing-nin. Tsunade withdraws from life as a ninja and departs from Konoha following the Second Shinobi World War


Temari and Shikamaru is not the first time we see Shinobi marriages from different villages. Naruto's Mother, Kushina, was originally from Uzushiogakure (Land Hidden in the Whirling Tides)


  Kushina Uzumaki was a Konohagakure kunoichi who originated from Uzushiogakure's 
  Uzumaki clan
  
  ...
  
  Born into the famed Uzumaki clan of Uzushiogakure, Kushina lived most of her youth being caught up in war, making her seek for a daily peace. At a young age she was sent to Konoha and enrolled in the Academy


However Uzushiogakure was also apart of the Land of Fire, they were different villages. 

Also, we have see other instances where Shinobi immigrated into other nations. One example is when Jiraiya first used Rasengan against some gansters


  The boss use to be a Chūnin from Hidden Village of the Stone


The Hidden Village of the Stone resides in the Land of Earth