Purple beans are made purple by anthocyanins. They create blues, purples, and some reds in many different flowers, fruits, and vegetables. However, they are pH sensitive, where in higher pHs they lose their color completely. Purple beans turn green because in the heat of cooking the anthocyanins are broken down, reducing the amount of purple production and also decreasing the acidity changing the purple to clear, which leaves the green visible. You may be able to counteract some of this cooking less (to reduce anthocyanin breakdown) and soaking lemon juice or vinegar before cooking (to increase acidity) ... or just eating them raw would certainly solve the issue.
Anthocyanins are harmless and flavorless, so they are perfectly fine for piggies.
Other examples of anthocyanins at work:
Hydrangea macrophylla can have red, pink, purple or blue flowers depending on the soil they're grown in. (Actually metalloanthocyanins, which involve metal ions in addition to the anthocyanins ... I think it's usually aluminum ions in hydrangeas.)
Purple cabbage will become colorless when cooked. So too can purple peppers and grapes lose their color. (Red peppers keep their color because the red in peppers is created by a different compound.)