Switching pronouns mid-sentence
I know that switching pronouns when referring to the same subject mid-sentence is considered grammatically incorrect, as in,
It is very easy for one to open a program in our newest operating system, all you have to do is click the corresponding icon.
where the pronoun referring to the subject changes from "one" to "you".
Are there any situations where it is appropriate to switch? For example, should the sentence,
If it is a boy, name him Moses; if it is a girl, name her Zipporah.
be rephrased like this or not?
If it is a boy, name it Moses; if it is a girl, name it Zipporah.
Your second example definitely does not need to be rephrased, and in fact the rephrase given should be outlawed on style grounds. Performing it would be a textbook overcorrection and overapplication of the "rule" about switching pronouns.
If you require a justification, try this one: you are not actually switching pronouns at all, because a hypothetical boy-child and a hypothetical girl-child are clearly not the same entity, so you are not referring to the same subject using different pronouns.
That justification is really nonsense, though. The real operating principle is that the pronoun-agreement rule exists to prevent the grammar and style of your prose from being degraded by shifts in the subject you are addressing. Losing the spirit of the thing in an attempt to consistently apply the letter of the rule results in the failure of its original purpose.
Your second example is fine and in fact the third would probably be considered ungrammatical by many speakers.
Remember that "it" doesn't actually have to be referential. In your second example, the "it" of "it's" probably doesn't actually refer to the baby: it's effectivly a dummy pronoun as in "It's important to take action". So there's no contradiction in having "it" and "him/her" in the same sentence: they're not coreferents.
Compare:
If it's twins, call them Mary and Josephine.
If it's sausages for dinner, make sure you get some mash to go with them.