The effect of compression on the magnetic ground state of Sr$_2$IrO$_4$ is studied with x-ray resonant techniques in the diamond anvil cell. The weak interlayer exchange coupling between square-planar 2D IrO$_2$ layers is readily modified upon compression, with a crossover between magnetic structures around 7 GPa mimicking the effect of an applied magnetic field at ambient pressure. Higher pressures drive an order-disorder magnetic phase transition with no magnetic order detected above 17-20 GPa. The persistence of strong exchange interactions between $mathrm{J_{eff}}=1/2$ magnetic moments within the insulating IrO$_2$ layers up to at least 35 GPa points to a highly frustrated magnetic state in compressed Sr$_2$IrO$_4$ opening the door for realization of novel quantum paramagnetic phases driven by extended $5d$ orbitals with entangled spin and orbital degrees of freedom.