It sounds pretty harsh, but the rough answer to your question is: It's always in the second position, with some exceptions.
Yes, it's an hyperbole. But the truth is that the verb is more often in second position than not. So, the question had to be: when is it not in the second position? And the popular examples are: questions, imperative and subordinate clauses.
Now, let's get to your example. Beforehand, you can find a very thorough answer by browsing on canoo.net. Once you understood the idea of Stellungsfelder and the Vorfeld, you will fully comprehend it.
In your example, the subordinate clause takes the position of the Vorfeld. That means that the whole subordinate clause takes the first position. Hence, the verb is in the second position if it comes immediately after the comma.
What you really need to remember is:
- The common sentence structure for a main clause is that the subject precedes the predicate. You can change the word order in many ways, but the verb stays in the second position in a declarative sentence.
- If the main clause comes first and you follow the common sentence structure (which is most natural in your example), subject comes before the predicate.
Wir gingen in den Wald, während sie aßen.
- If the subordinate clause comes first, subject and predicate are swapped.
Während sie aßen, gingen wir in den Wald.
That all being said, there's also another view at it. You can also consider it one of the exceptions where the verb comes in first position.