Why Did God Command Hosea to Marry an Immoral Woman?

What would you say if a Christian friend claimed God had told him to marry an immoral woman? To say the least, you’d have reservations, right? You’d probably tell him what the Bible says about being “unequally yoked” and warn him of the dangers of missionary dating.
But what should we make of the fact that God seems to have told Hosea to do exactly that? The prophecy of Hosea is probably best known for the scandal of Hosea’s marriage to Gomer. So the question is straightforward: Why did God command his prophet to marry an immoral woman?