Ego could destroy Thanos, but he was also about to take out various planets, including Earth. As someone already said, Ego needed to be taken out and was not someone that could just contain.
Ego and Thanos would’ve been a nice fight to see and many argue over who the victor would be. It is simply not possible because they killed Ego due to the fact that if they hadn’t he would’ve wiped out numerous planets, Earth included and many people would’ve died.