He never 'turned hetero'. He has always been gay, he just wanted to be 'normal'
there are small instances where the characters experience homophobia (also through Shun's eyes) and it seems like Nagisa has a tense relationship with his parents so it felt like he wanted to rub that child and marriage in their faces and not have to be prejudiced against or joked about. In the prequel there was a similar situation where he dated a woman just to appear more 'normal', so i guess he kind of went back to it when he realized he would be more accepted if he appeared straight. Things changed because he not only grew up more and i guess also outed himself but also because he was in a relationship with a man, so i guess he had to explain himself or out himself.