The novel is set in France (and occasionally England) in the 1620s. Specifically, the backdrop is the Siege of La Rochelle, during which King Louis XIII defeated the Huguenots of La Rochelle. King Louis XIII derived his power from the Catholic Church. The Huguenots, as a Protestant sect, were a threat to this power. The 1598 Edict of Nantes supposedly ended the religious conflict between Catholics and Protestants in France, giving the Huguenots limited powers to rule themselves in the city of La Rochelle as long as they confined themselves to their assigned territory. But regime changes led to further conflict in the Thirty Years' War, when King Louis XIII and Cardinal Richelieu tried to force Huguenots back under Catholic rule. The Cardinal initially courted England's support, but England eventually got involved on the side of the Huguenots, encouraging rebellion to destabilize France's power. The actual Siege of La Rochelle took place in 1627 and 1628, in the middle of the Thirty Years' War.
The novel draws its characters from the main players in this conflict. The king and cardinal, for instance, are both prominent characters. The way characters are always changing their alliances based on what is most advantageous for them in the moment emphasizes that the Thirty Years' War was at least as much about power as it was about religion. For example, Cardinal Richelieu and the king work both for and against one another in the book, depending on what suits them. Cardinal Richelieu especially seems to have no problem acting against the teachings of Catholicism when it will help him gain more power. The musketeers are happy to align themselves with the Duke of Buckingham when they are trying to help the queen, but they have no sense of loyalty to him. D'Artagnan is even happy to make an alliance with the cardinal at the end of the novel, despite all of the terrible things the cardinal has done. The many shifting alliances over the course of the Thirty Years' War are ample fodder for Dumas to depict comically fickle politicians.