The backstage model of torpedoes is that they use the contents of their warhead as fuel for the propulsion system. So, a torpedo at the end of its run would have zero explosive yield, unless specifically commanded to retain some of the fuel.
OTOH, it would take a lot of time for a torpedo to reach a planet by aimless drifting - quite possibly billions of years. It sounds likely that the onboard containment field for the antimatter charge would decay and fail in a matter of months, weeks or perhaps days already, even if not specifically commanded to.
I do wonder what happens to phaser beams that miss... Supposedly, they don't simply snap out of existence when the firing emitter is turned off (we have seen phaser pulses with front and aft ends flying through space, after all). Running into one would be phenomenally bad luck, but the process in itself is intriguing.