How should one play against unexpected opening variations?
In short: calmly. In general, but especially in an opening you've prepared, the best defense against an unexpected move is to figure out the answers to two natural questions:
What is the purpose of this deviation? A threat? A trap? Perhaps your opponent wants to transpose into a line that's more comfortable for him, or less comfortable for you. Whatever the case, try to see what your opponent hopes to gain.
Why isn't this a common variation? Why didn't you come across it in your studies? Especially in the opening, if you encounter something unexpected, it's probably because it isn't as strong as the main lines. Try to see why: maybe it's an easily-refuted threat, or a loss of time, or it weakens your opponent's long-term position.
When you've answered these questions, if you've identified a credible threat, you must of course meet it. But if you can't determine an obvious threat posed by the unusual move, the best course is usually to relax and continue to make good, solid opening moves. Trust your fundamentals: they're guidelines that exist for a reason. Keep developing your pieces to good squares and watch for anything else unexpected. If you identified a weakness in your opponent's unusual move, take advantage of it where you can.
For example, given your opening of choice, a little-used variation of the Ruy Lopez:
1.e4 e5 2.Nf3 Nc6 3.Bb5 Qe7
Here, Black chooses a very unlikely third move. It doesn't pose any immediate threats (1), and it hinders his development by blocking in the King's Bishop (2). There's nothing White can do at the moment to take advantage of this strange choice directly, so he should continue with simple, easy development. 4.O-O
leaves the BQ staring at nothing in particular. After the most common continuation, 4...Nd8 5.d4 c6 6.Ba4
, White has done nothing special at all, but he's ahead in development while Black struggles to organize his troops.
1.e4 e5 2.Nf3 Nc6 3.Bb5 Qe7 4.O-O Nd8 5.d4 c6 6.Ba4