What is the in-game context that decides what dialogue is used? Or do they just choose at random from a dialogue bank?

Outside of holidays and special events, they do indeed choose randomly from a dialogue bank. There’s actually multiple dialogue banks, one for each villager personality type.