Suggestion 1.
Difficult to say, but for a pure liquid (particle free) a pilot or spring operated pressure reducing valve will close the inlet to the pipeline at a preset pressure, and open the inlet at a (lower, because of hysteresis) pressure.
Two problems to be solved
a) Particles must be filtered out before the control valve.
A multitude of commercial available solutions and filters exists.
b) Gas must be bled out before the valve. If the gas is air, or even by other gases, there is again a multitude of outlet valves and methodes.
How often will this pressure peak occur? Only safety measure or repetitive in some way?
Suggestion 2
Connect a pressure switch to the pipeline, pressure switch with flush face for contaminated fluids. If no available electrical supply arrange with battery operated solenoid valves to open when pressure switch reches preset value, to feed air from air accumulator to operate suitable air operated shutdown valves, placed where suitable.
If away from normal pressurized air resources the accumulatur could be refed with pressurized air from pump, nearest gas station or a separate small compressor.
It is not necessary to do anything with the fluid in the pipeline.
Suitable air operated valves: single or double acting ballvalves should work.