Yamato was given a mission to spy on Orochimaru. This happens at the end of Naruto Shippuden after the war.