In medieval times, although gentry had plenty of rich food, the commoner would need to stretch the food. She would keep an iron pot on an open fire and throw all of her leftovers into it each day. It simmered most of the time. - sometimes for days. Then if someone arrived unexpectedly, he was likely to have to eat from the pot without knowing what had gone into it.
So, taking "potluck" came to name the act of eating any meal for which the host or hostess has made no special preparation.