When do I have to use
そうですか。
and
そうなんですか。
?
When you have to use? Well, any time you want to, as long as you mean "is it?" or "is that so?" ;-)
So much for kidding.
Do you want to differentiate between the two? They mean the same thing, with the latter revealing a bit of surprise/scepticism/unexpectedness etc, depending on the context.