Each inhabitant of a remote village always tells the truth or always lies. A villager will give only a “Yes” or a “No” response to a question a tourist asks. Suppose you are a tourist visiting this area and come to a fork in the road. One branch leads to the ruins you want to visit; the other branch leads deep into the jungle. A villager is standing at the fork in the road. What one question can you ask the villager to determine which branch to take?

as answer of this question given in rosen is

“If I were to ask you whether the right branch leads to the ruins, would you
say 'yes'?”

how this question arise and please explain the reason about this answer to above question

There are many correct answers to this problem. Still, all involve double layering or combining a question about the kind of person being addressed with a question about the information being sought. One solution is to ask this question: "If I were to ask you whether the right branch leads to the ruins, would you say 'yes'?"

If the villager is a truth-teller, he will reply "yes" if and only if the right branch leads to the ruins. Now let us see what the liar says. If the right branch leads to the ruins, he would say "no" if asked whether the right branch leads to the ruins.

Therefore, the truthful answer to your complicated question is "no." Since he always lies, he will reply "yes." On the other hand, if the right branch does not lead to the ruins, then he would say "yes'' if asked whether the right branch leads to the ruins; and so the truthful answer to your question is "yes"; therefore, he will reply "no." Note that in both cases, he gives the same answer to your question as the truth-teller; namely, he says "yes" if and only if the right branch leads to the ruins

For the sake of simplicity suppose the left branch leads to the ruins whereas the right one leads you lost deep into the jungle...

Case 1. The villager is a liar: in this case, since he knows the right branch leads to the jungle then he'd say it leads to the ruins, but he won't tell you NOW this, so his answer here is NO....

Case 2. The villager tells the truth: he will answer NO again, 'cause he knows the right branch takes you to the jungle and he will let you k now that...

From the above, it's clear you must choose THE other branch if the answer is NO....