“You're welcome to stay for dinner.”
A friend came to your house to bring back some books she was borrowing from you. You were cooking dinner when she came over. You want to be polite, so you invite her to eat dinner with you.
You're welcome to stay for dinner.
This is a way to offer something to someone:
You're welcome to use my car if you need to go anywhere.
You're welcome to come with us if you want to.
Offering things in this way is friendly and low-pressure. In other words, it doesn't make the listener feel like they have to accept the offer.
When someone visits your home in the afternoon, you can invite them to "stay for dinner". That means that they weren't planning on eating dinner at your house, but they did.
Here are some examples in sentences:
Why don't you stay for dinner?
Masa and Irene came over in the afternoon and ended up staying for dinner.