So, if you look at it from an in universe type of way, I think it's a combination of a few things.
We seen time and time again how Goku can change people, his kind heart and just way of life brings something out of people that is hard to explain, I think that surely played a huge part Then you look at all the training he did with Trunks during the lead up to fighting Cell, where he still was kind of a dick and everything, you see how much he had changed when he snapped seeing Trunks get killed, if he was still his heartless evil self at that point, he wouldn't have really cared all that much. But he still wasn't what I'd call a good guy or a hero at that point, just not really a bad guy. Then the life he spent during the time skip with his family, that helped soften him up. I mean there is stuff there during that time skip from the end of Cell, to the Buu Saga that we miss, and who knows what all happens during that time, but family life surely played a huge part in it. So I don't think it's just one thing that changed him, but just everything around him as a whole that took him from an evil planet conquering villain, to one of earths mightiest heroes.