You just have to carefully follow the method calls. When fun(5) is called it prints out 5, then subtracts 1 from 5 and then calls fun(4). Now it prints out 4 and calls fun(3). It does this until it reaches zero. Once it stops calling fun(x) you have to backtrack through the method calls for the second print statement.
The most recent method call was fun(1), where the value of X now equals zero so it prints out returning 0. The second most recent call was fun(2) so it prints out returning 1. And so on. Each method is never completed until you backtrack through all the other ones.
It's kind of hard to explain, try drawing out the method calls to make it easier to understand. It is basically the fundamental property of recursion.