In UBW episode 25 whenever the sun rises/sets Rin looks at it with a sad and lost in thought expression. Why does that happen?
The reason is because she remembers Archer. I'm gonna answer you referencing the visual novel as it is much easier to me. Notice that this conversation with Archer takes place in both endings, not just the true ending (visual novel source). The first time we see Rin doing that is one month after the Grail War.
As you can see Rin is lost in thought. Then he says:
"Track team? No, I was always in the archery club." "…I see. Well, I guess there are times like that. Seeing the setting sun just reminded me." Telling me to forget about it, Tohsaka continues to drink the orange juice.
That is the scene Rin was looking at. As you can see the sun is setting. Just after this CG Shirou thinks about archer:
"I recall that red figure one more time. Neither this classroom nor that fight will change. Everything is the same. Everything is an illusion like a mirage that disappears when one turns around."
As you can see there is a setting sun. In UBW Rin has been seeing this scene in her dreams many times. Just like Shirou and Saber were connected in the fate route through dreams, Rin and Archer were connected in this route and she kept dreaming about Archer and those swords in a rising or setting sun.
I am sure she's thinking of Archer because he's the ONLY character that has made Rin cry. Rin never cries. She's always cold or even if she's not she just takes action, no one breaks her enough to cry. Throughout the WHOLE game Rin has only cried 3 times, all of them in UBW, she doesn't cry in the fate route nor in Heaven's Feel.
The first time she cried was when having a dream about Archer. She woke up in tears, brushed them off and tried to start the day normally. Notice that a dent had already created. This time was just unconcious crying in a dream.
The next time she cried was when archer betrayed her to join caster. She told him that he's hers and that she would recover him and he'd regret what he did (as you can see these aren't exactly vengeful words. Seems more like she's gonna scold him). Once Shirou tries to protect her he says some words to her and she starts crying. Later she hugs Shirou. Notice that this time 2 people made her cry: Betrayal by Archer and Shirou being there risking his life for her.
The last time she cried was the longest time Rin has ever cried. It was her farewell to Archer. Notice that this part will be the real answer to your question.
She begs him to form a contract with her: "Archer. Form a contract with me again."
"I cannot do that. I do not know if you will keep your contract with Saber, but I am not qualified for that. And I do not have a goal anymore. My battle ends here." His reply is free of doubt and his will is strong. His face is as bright as the rising sun, and how can she force him when he's making a face like that?"
Notice that Rin even thought about forcing him but saw there was nothing she could do. Notice the reference to the rising sun. Rin thinks: "His face is as bright as the rising sun".
All the time Rin is crying. Rin just cries for Archer:
"Man. I do not have any attachment to this world, but…" It's troubling to have her cry. For him, the girl always has to be a positive, indulgent realist. He was always encouraged by her figure. So he wants her to stay that way until the very end"
Notice that Rin changes for Archer/Shirou as Archer thinks. She's always realistic, never crying amd always taking action.
She knows Archer is not really Shirou, even if they had the same starting point. Her archer is a different person that she loves dearly and will never return.
…The future might change. If a girl like her stays with Emiya Shirou, the hero Emiya should not be born. His words contain such hope.
Notice that this CG appears A LOT. I remember thinking back when I played the VN that it was a very annoying CG. I think they showed the rising sun over 10 times. It always went lik this: Image of Rin and Archer - Image of the rising sun; image of Rin and Archer - Image of the rising sun and many times.
Even 2 years after that she still makes that look when the sun is either setting or rising.
Last of all, you didn't ask about it but Shirou makes sad faces as well. He's thinking about saber. At almost the beginning of the episode Rin asks Shirou to take a walk in the park after classes. He makes a sad expression and says it's nothing. Rin then makes a look of understanding. The next day Rin takes Shirou to Glagow to allow him to pay his respects to Saber. “You remember how you told me that day that you wished you had the chance to say a proper goodbye. Now’s your chance”. Once they reach the tomb Rin says: “I’ll give you some time alone” and goes away to prepare the picnic. Shirou then says his goodbye words in front of her tomb. At the end he says: “Thanks for taking me there, it means a lot”.
In the happy ending he gets saber so that won't happen. Rin will still feel sad when the sun rises or sets though.
There is another reason for her to be sad (apart from the one already said in the other answers). It would Shirou leaving the Clock tower. It would make her unhappy all the time.
At the beginning of the episode Rin is super happy. There's a blue sky and she runs with Shirou towards classes and smiles to him while asking him to walk with her after classes. But seconds later Shirou makes a sad look. A bit later Rin asks him to join the Clock Tower and sells it well:
Joining the magic assotiation isn't without its perks. As a matter of fact most people would jump at the idea
Yeah, I guess you're right...
This would be Rin's happy ending. The other heroines get similar treatment. Saber and Shirou live in Avalon for all eternity after the fate route and Shirou and Sakura live in the Emiya house and he gives up being a hero. This is what Rin was gonna do, be happy with him in the Clock Tower.
But then she remembers Archer. The next morning Shirou wakes up and Rin is besides him. It would appear she had been there for a while so maybe she had been looking at the sunrise while he slept. My guess is that she remembers Archer. She had promised him to make Shirou happy, so she takes him to see saber. Rin knows this will sway Shirou's mind towards what he really wants and it certainly does. When they return Rin's head is in Shirou's shoulder. She feels vulnerable and sad because of what her decision is gonna do.
The very next night Shirou says he has made up his mind to leave the magic Association. He asks:
Aren't you surprised?
Of course she wasn't, the visit to saber was so that he chose the path that leads him to happiness. She had had 1 whole year in London to visit Saber and she didn't (Shirou apparently didn't have the general knowledge that that place exists). Even though Rin says it's so that he can pay his respects to saber and he says thank you for taking me there, it means a lot, it has nothing to do with that. It is just for Shirou's happiness (against her own).
At the end of the episode she had probably been looking at the sun setting while waiting for Shirou. It reminds her yet again of Archer. She then says sweet things:
It will all lead to our happily ever after, I just know it
She also says she's gonna follow him. And at the end him (Archer) is smiling. Solitude was Archer's problem, now that Shirou has Rin by his side he can be a happy hero.
In Fate hollow Ataraxia (I haven't read it but I've seen the scene in youtube) there's a scene where we see future Rin. She says that she will give Shirou happiness more than anyone. His happiness comes before her own.
Conclusion: The beginning of the episode is the reality. Rin is very happy. She goes to her studies running and turning around and smiles to Shirou when telling him to take a walk with her after classes. The problems come when Shirou makes his sad face and Rin faces reality, that being together in the Clock tower is her dream world, not his. Giving up on that hurts her (specially since he had pretty much agreed to it), that's why she starts getting sad the following 2 days all the time.