Depth-resolved Raman piezospectroscopy was used to study residual mechanical stress profiles in polycrystalline silicon and aluminum nitrides irradiated with 710 MeV bismuth ions to fluences of 1×1012, 2×1012, and 1×1013 cm-2. It was found that stress fields of opposite signs are formed in the irradiated Si3N4 layer, separated by a buffer zone located at a depth coinciding with the thickness of the sample layer, amorphized at high ion fluences due to multiple overlapping of track regions. At great depths, tensile stresses witch magnitude reaches their maximum value in the region of the end of the ion range are detected. In contrast to Si3N4, radiation-stimulated changes in mechanical stresses in AlN were within the measurement error throughout the entire thickness of the irradiated layer, except of the near-surface region. The observed effect is associated with the different structural sensitivity of silicon and aluminum nitrides to high-density ionization - the formation of amorphous latent tracks in Si3N4 and their absence in AlN.