Carlos II was far worse off than simply 'mad'. He had such an undershot jaw he could barely speak or eat. Crippled, obese, drooling, he seems to have been either seriously damaged, retarded, or both.
His father was his mother's uncle, and they were so closely related they might as well have been both full siblings and father/daughter. At his birth rumors ran wild that he wasn't a living human, and might even be *gasp* a girl. With the future of the vast Spanish Empire at stake, the truth had to come out. Felipe IV permitted the French ambassador to see him. As time went on, the rest of Europe began to know the ugly truth about the Infante.
Carlos eventually married Louis XIV's niece, a beautiful, intelligent young lady whose life as Queen was a living hell. Carlos, slobbering and impotent, desperately tried to have children with her, but naturally (and fortunately) nothing happened. Her parrot was strangled for speaking French. When she died, it was widely believed throughout the Royal houses that she'd been poisoned.
Carlos lingered on for years. When he finally died, he named his French cousin Phillippe, Duc d'Anjou, as his heir, which is why El Rey Juan Carlos is a Bourbon and not a Hapsburg.