Why do red onions turn blue or green when cooking sometimes?
The pigments that give onions the colour behave like a litmus test. They are red in the naturally acidic onion. They turn green/blue in an alkaline environment. It sounds like when you cooked the beans it created that alkaline environment to cause the colour change.

See Here.