Aims. We aim to probe the magnetic field geometry and particle acceleration mechanism in the relativistic jets of supermassive black holes. Methods. We conducted a polarimetry campaign from radio to X-ray wavelengths of the high-synchrotron-peak (HSP) blazar Mrk 421, including Imaging X-ray Polarimetry Explorer (IXPE) measurements from 2022 December 6-8. During the IXPE observation, we also monitored Mrk 421 using Swift-XRT and obtained a single observation with XMM-Newton to improve the X-ray spectral analysis. The time-averaged X-ray polarization was determined consistently using the event-by-event Stokes parameter analysis, spectropolarimetric fit, and maximum likelihood methods. We examined the polarization variability over both time and energy, the former via analysis of IXPE data obtained over a time span of 7 months. Results. We detected X-ray polarization of Mrk 421 with a degree of ΠX = 14 ± 1% and an electric-vector position angle ΨX = 107 ± 3 in the 2-8 keV band. From the time variability analysis, we find a significant episodic variation in ΨX. During the 7 months from the first IXPE pointing of Mrk 421 in 2022 May, ΨX varied in the range 0 to 180, while ΠX remained relatively constant within ∼10-15%. Furthermore, a swing in ΨX in 2022 June was accompanied by simultaneous spectral variations. The results of the multiwavelength polarimetry show that ΠX was generally ∼2-3 times greater than Π at longer wavelengths, while Ψfluctuated. Additionally, based on radio, infrared, and optical polarimetry, we find that the rotation of Ψoccurred in the opposite direction with respect to the rotation of ΨX and over longer timescales at similar epochs. Conclusions. The polarization behavior observed across multiple wavelengths is consistent with previous IXPE findings for HSP blazars. This result favors the energy-stratified shock model developed to explain variable emission in relativistic jets. We considered two versions of the model, one with linear and the other with radial stratification geometry, to explain the rotation of ΨX. The accompanying spectral variation during the ΨX rotation can be explained by a fluctuation in the physical conditions, for example in the energy distribution of relativistic electrons. The opposite rotation direction of Ψbetween the X-ray and longer wavelength polarization accentuates the conclusion that the X-ray emitting region is spatially separated from that at longer wavelengths. Moreover, we identify a highly polarized knot of radio emission moving down the parsec-scale jet during the episode of ΨX rotation, although it is unclear whether there is any connection between the two events.