Beans are very high in fiber and can really get your bowels moving and cause lots of gas pains depending on how many beans you eat.
I can only eat a small portion of beans at one time otherwise I get bloated and then have lots of gas which leads to diarrhea as well later.
Beans can upset the digestive tract which is likely why they suddenly caused you diarrhea which is usually nothing to worry about.
You may have just eaten too many beans at one time which upset your stomach and got your bowels moving.
Or you could also have Celiac Disease which is an immune reaction to eating gluten which is a protein found in wheat, barley, and rye.