Charles II was not sterile; he fathered many bastard children through multiple mistresses. Charles sired five children by his mistress Barbara Villiers between 1660 and 1668. Charles kept several mistresses throughout his reign, granting them titles, and giving gifts worth thousands of pounds. According to Harris' Restoration, Charles II sired at least 14 children in his life.
The most famous of all of Charles' bastards was James Scott or Crofts, Duke of Monmouth. Monmouth was born in April, 1649 to Charles' mistress Lucy Walter, while the King was living in exile following the Regicide. Charles often treated Monmouth like he was the Prince of Wales and heir, but Charles took no action to make Monmouth's birth legitimate. Monmouth was also a firm protestant, making him an ideal choice for a king by the more radical nobility (or perhaps the more anti-Catholic nobility). When Charles died in February of 1685, it was clear that his brother James would succeed him. By the summer, Monmouth had set up an invading force to take the crown back from a Catholic heir. Monmouth was defeated, and following the failed rebellion, hundreds of rebels were executed or sold into servitude in the Caribbean. Monmouth was also executed to prevent him from trying to further his claim to the throne.
In all, if anyone was sterile in the relationship between Charles II and his Queen Catherine, it was more likely the latter. Charles had proved his ability to sire children a decade before his marriage to Catherine. Rumors arose a few years into the marriage that Catherine was infertile. In her ODNB entry, Wynne suggests that Catherine's infertility was well known outside of the palace, and that her condition may have been the result of excessive uterine bleeding. Charles and Catherine's marriage was strained under the duress from the lack of a clear legitimate heir, and likely contributed to Charles taking on more and more mistresses, including women like Frances Stuart, the maid of honour in the Queen's household.