Good question. You may find that some native speakers use these interchangeably.
Doing good to someone means that they are the direct recipient of the benefit of your action. For example, if someone is hungry and you give them something to eat.
Doing good for someone means that they are an indirect recipient of the benefit of your action. For example, if someone is hungry and you give money to a charity that provides food.
Doing good by somone means that their situation may be improved as a consequence of your actions (so your actions are guided by a respect for their situation). For example, knowing that someone is hungry you resolve not to waste food or to campaign for restaurants to provide surplus food to a charity.