If not dynamite, then something similar like a bomb from the DMG.
Both have a similar rules text:
As an action, a creature can light a [stick of dynamite/bomb] and throw it at a point up to 60 feet away. Each creature within 5 feet of that point must make a DC 12 Dexterity saving throw, taking 3d6 [bludgeoning/fire] damage on a failed save [./, or half as much damage on a successful one.]
Nothing there says it targets/counts as an attack.
The spell Sanctuary says:
If the warded creature makes an attack, casts a spell that affects an enemy, or deals damage to another creature, this spell ends.
Do the rules consider you having dealt damage once the explosive goes off? Is it any different if you set the dynamite to explode after a set number of rounds (assuming you are still under the effects of sanctuary), and perhaps an innocent bystander walk by while you aren't looking?