When potatoes do this, it is known as “greening” or sometimes “sun-burning”. It happens because the potato was exposed to light for an extended period of time. The green is chlorophyll which, as most know, is a plant’s “food”. The green chlorophyll is absolutely harmless.
However, during the biosynthesis of chlorophyll, a glycoalkaloid known as “solanine” can, and most often, will be produced. Solanine is poisonous, and is the plant’s (any plant's) defense mechanism against predators. The production of solanine is independent of chlorophyll production and can happen at any time, even when there is no greening. Greening is not required for solanine to be produced in potatoes, however, typically solanine production does rise when there is greening.
Solanine is concentrated in the skin and typically no deeper than 1/8” into the underlying flesh of the potato. This is because that is where it will benefit the potato most as a defense mechanism. Removing the skin and some of the underlying flesh will remove the solanine, but cooking the potatoes will not affect solanine concentration at all, so it is best to peel any green potatoes....and peel them down to pure flesh (no green). But remember, solanine is not the green part.....that is chlorophyll which is harmless.
Solanine is bitter, so if a potato tastes better, then do no eat it. You would have to eat a considerable bit of a fully green potato (including the skin) to get a reaction. A 200 lb person would need to eat at least 2 pounds of green potatoes to get the basic reaction of nausea, cramping, loose bowels, etc. A fatal dose of solanine would be very hard to achieve with green potatoes alone.
To avoid greening, store potatoes away from light, especially fluorescent lights. If there is greening, simply peel the potatoes and remove all green and you’re good to go. If the potato ever tastes bitter, then don’t eat it.
Interestingly enough, many people have probably seen this happen on potato chips....ever gotten a green chip from a bag or a chip with green edges? That’s greening. Same with french fries.