Good question! And one every GM has to deal with from time to time I would think. I'd probably pick one or two of these:
Keep the pace. Part of your story revolves around urgency. Let them feel stressed out, make your encounters heave for breath, more so the closer the party gets to the final boss fight. Try to make them feel guilty for even the slightest pause, thorough searching etc.
Help them recover. Let the PCs discover an old and forgotten crate with a nearly empty healing wand, some crumbling restoration scrolls and a six-pack of useful potions with faded labels.
Surprise the badguys. Villains also need to deal with changing schedules.
- An important ritual component is lost or spilled on the floor during preparation and a minion is dispatched to the nearest town to procure more.
- A pair of blundering ogres accidentally discover the villains hideout and must be dealt with, depleting resources.
- A cloudy night sky diminishes moon power, so the ritual is postponed for a day or two until weather clears up.
- The players can mess up the villains schedule. Give them a chance to funnel a swarm of dire bats into the villains part of the dungeon, thus creating havoc and buying time.
Yes, it may cast spells. (Usually)
There is no text stating the creature is incapable of casting spells, with the exception of the Chain (which some DMs may rule prevents somatic and material spells due to being restrained, although note this is not RAW), and Slumber (which causes the target to sleep, being incapacitated)
You create a magical restraint to hold a creature that you can see within range. The target must succeed on a Wisdom saving throw or be bound by the spell; if it succeeds, it is immune to this spell if you cast it again. While affected by this spell, the creature doesn’t need to breathe, eat, or drink, and it doesn’t age. Divination spells can’t locate or perceive the target.
For the Gem containment:
Minimus Containment. The target shrinks to a height of 1 inch and is imprisoned inside a gemstone or similar object. Light can pass through the gemstone normally (allowing the target to see out and other creatures to see in), but nothing else can pass through, even by means of teleportation or planar travel. The gemstone can’t be cut or broken while the spell remains in effect.
Emphasis mine. Note the creature is aware, but nothing can pass in or out of the gem prison, including planar transport. This would include most spell effects, although there could be an argument made for very specific spells, such as Telepathy, or as mentioned in another answer, light based spells.
Additionally, in all cases but Slumber (and maybe Chains depending on DM), if the caster is powerful enough to cast spells of 9th level, and has Dispel Magic prepared, they would be capable of freeing themselves from the prison by casting Dispel Magic as a ninth level spell at their prison.
Note: In all cases, planar travel and teleportation is restricted.
Finally, which spells could potentially affect the prison or outside world depends on the prison chosen, and your DMs judgement.
Best Answer
Yes, it is affected. Although the immunity rule is somewhat open-ended, the general idea is that a creature cannot be harmed by or gain conditions from whatever they are immune to. The stone golem's ability is special:
It then lists some damage and debuff spells that have secondary effects.
Luckily for you, Sanctuary does not allow spell resistance, and does not impose a specific condition or harm an attacking creature. Additionally, none of the golem's construct traits apply to the effects of Sanctuary, and so it would still need to pass the Will save to hit you. Good luck!