Can random foreigners join a Sri Lankan village wedding?

Yes, if the family explicitly says you can come, foreigners are more than welcome to be included in a Sri Lankan village wedding, because the culture is really hospitable and kind of proud to show its traditions. Still, you can’t just wander in or accidentally crash a wedding without an invitation, not even “for a minute” or so.

It’s also very normal for travellers who are staying in a local guesthouse, or just chatting with friendly residents, to get a spontaneous invitation to some nearby celebration. If you get invited, it’s the usual thing to dress modestly (a saree for women, and for men, smart trousers with a collared shirt) and to bring a small amount of cash in a decorative envelope, so you can give it to the couple.