The movie takes place in 1660, which is consistent with King Louis XIV's age in the film and with the presence of his mother, who died in 1666. One of the few things known about the real-life man in the iron mask is that he was not arrested until 1669. In the film, Philippe was a prisoner for years. Also inconsistent with the 1660 date is the war against the Dutch, 1672-1678.
This all makes sense, but I think they were doing it for dramatic purposes, not to be historically correct. If this was a history movie, it would be one thing, but it's only for entertainment, so those kinds of things can slide.
Alexandre Dumas, the original author of this fair story and others (including the three musketeers) was known as 'The great Rapist' of French history, borrowing unashamedly from different parts of history without any regard for continuency. In fact in later stories even D'Artagnan and Richelieu's top henchman are actually great friends and is accidentally killed by D'Artagnan.