We went to dinner (at the pub). Our friends came to dinner here.
We went (to the pub) for dinner. We had our friends over for dinner.

So which idiom you use depends on what your cousin actually did. If she came in order to have dinner with you, use for. If she just joined you at the pub to enjoy your intellectually superior conversation, use to.

Formally, if you use the for construction it should be attached to dinner rather than pub:

We went for dinner, for which my cousin came along, at a nearby pub.

But conversation is not so exacting. And in fact, colloquially, what I've given you here are more ‘as-a-rule’ or ‘rule-of-thumb’ than Rules. Nobody will raise an eyebrow, or even notice, if you say “We had our friends over to dinner” or “We went to the pub to dinner”, any more than they'll snigger at your ending a sentence with a preposition. You often start a sentence going in one direction and end up going in another, and in conversation you don't get to go back and rewrite the beginning. You can of course in a email; but nobody† does. Nobody cares.

† Well, I do; but I’m a professional writer and have a reputation to prop up.

The "Before that, we went for dinner at a nearby pub for which my cousin came along" sentence should be reordered: "Before that, we went to a nearby pub for dinner, for which my cousin came along." That should solve the problem, but it does create another one: "...for dinner, for which..." So you can use "to which my cousin came", "which my cousin joined us for", "Before that, we went, with my cousin, to a nearby pub for dinner.", or "Before that, X, my cousin, and I went to a nearby pub for dinner."

Maybe Last night I went to the theatre to see a play with X should be reordered as well: "Last night, X and I went to the theatre to see a play."