My wizard has a Staff of the Magi one and is itching to break it over his knee. But he values his life and wants to maximize his chance of survival. If he casts Contingency with Dimension Door - specifying a location far enough away from the blast - there is an argument that the spell goes off before the explosion or possible Plane Shift. Does this work?
Yes, you will escape
The question, effectively, is "does contingency go off before the explosion happens", which means we need to look at the triggers.
When the staff is broken
Retributive strike (Ie: the name of the explosion)
You can use an action to break the staff over your knee or against a solid surface, performing a retributive strike. The staff is destroyed and releases its remaining magic in an explosion that expands to fill a 30-foot-radius sphere centered on it
So the trigger for both effects is when the staff is broken over your knee, which means both happen simultaneously! So how do you decide the order?
SIMULTANEOUS EFFECTS (XGtE page 77)
If two or more things happen at the same time on a character or monster's turn, the person at the game table - whether player or DM - who controls that creature decides the order in which those things happen
So since this likely all happens on your turn (unless you held your action, in which case, don't) you get to decide the order, and can choose for contingency to come into effect first.
Just note that content from XGtE is optional, so if it is not being used at your table then the default answer becomes: ask your DM. Rule 0 will then be in effect.
But it might not do what you think
When retributive strike is activated you have a 50% chance to instantly travel to a different (random) plane. This backs up my assertion that there is time between the break and the explosion, but there is no distance associated with that effect, so you may dimension door, but then still find yourself on another plane - possibly wishing you had used contingency for water breathing, fly, or some form of fire resistance instead!
The contingent spells occurs after the trigger
The part of contingency which is relevant here is the line (emphasis added):
The contingent spell takes effect immediately after the circumstance is met for the first time [...]
Which means if we specify the retributive strike as the trigger, dimension door would step into effect after the explosion and our possible plane shift.
We obviously can't have some trivial trigger before the activation, as then we'd dimension door too early. What you'd need for this to work is for the initial activation to be catchable by contingency and leave the explosion as a triggered ability to resolve after you've teleported. Unfortunately the action, trigger, etc. rules of D&D 5e simply aren't defined enough for this to have a clear answer. It'll fall to the DM, and where it lands between cool, fun, viable, cheese, etc. for your table.