You could use the ritual to break the forgetting spell as the trigger event, the townsfolk rise up against the hobgoblins creating the opportunity for the party to reach the evil Duke for a climactic battle. In that case, you need to delay the ritual. The obvious ways to do that are A) components, B) location, and C) timing.
Components would be unique or rare items that need to be obtained in order to perform the ritual. Each one can have its own mini-quest to get the thing, to gain the assistance of someone who has the thing, etc.
Location would be a specific location the ritual must be performed, the party must gain access (e.g. find out the location, get keys or find a secret back entrance, etc) and perhaps gain allies (e.g. maybe allies can distract the guards who would otherwise stumble upon the location during the ritual).
Timing would be a particularly auspicious time to perform the ritual. It could be that it will only work on a particular date, during a particular event (e.g. during an eclipse or meteor shower, or a holy holiday), or maybe there is a situational opportunity e.g. they need to do it when the Duke is away from the location and busy with some other thing. They may need to find out the date (e.g. they need a meteor shower but don't know when the next one will occur, or they don't know when the Duke's business will take him out of the city). There could be prerequisites or it could depend on their own actions, e.g. exactly 60 days after the reconsecration of the temple.
Or... maybe you don't want the ritual to trigger everything. Perhaps you've already given them the ritual information and it's too late to add those requirements, or maybe other dramatic reasons. In that case, it could be that removing the spell will prevent new arrivals from forgetting, but will not in and of itself restore any memories. Maybe it just makes it possible to restore the memories of individuals (with an item, a spell, maybe you need stories about that individual or a personal item from their past as a reminder). If you go with that, you could spend time letting them pick who are the most important allies they will need, figure out how to get to those individuals and how to restore them. These could be the individuals who can identify the time and date of the ritual, or provide the distractions; they could also be the people who give the players the clues about the Duke's true nature.