I think the point is that they didn't.
Google's motto is still "Don't be evil". Alphabet (Google's parent company) adopted "Do the right thing" as its own, but Google's is still in effect.
To answer the question of why "Do the right thing", it is in my opinion to support actions that they deem "right" or "good" which otherwise aren't strictly required for their operations. For example their support of gay marriage.