Recently, considering the temporary immunity of individuals who have recovered from certain infectious diseases, Liu et al. (Phys A Stat Mech Appl 551:124152, 2020) proposed and studied a stochastic susceptible-infected-recovered-susceptible model with logistic growth. For a more realistic situation, the effects of quarantine strategies and stochasticity should be taken into account. Hence, our paper focuses on a stochastic susceptible-infected-quarantined-recovered-susceptible epidemic model with temporary immunity. First, by means of the Khas’minskii theory and Lyapunov function approach, we construct a critical value {mathscr {R}}_0^S corresponding to the basic reproduction number {mathscr {R}}_0 of the deterministic system. Moreover, we prove that there is a unique ergodic stationary distribution if {mathscr {R}}_0^S>1. Focusing on the results of Zhou et al. (Chaos Soliton Fractals 137:109865, 2020), we develop some suitable solving theories for the general four-dimensional Fokker–Planck equation. The key aim of the present study is to obtain the explicit density function expression of the stationary distribution under {mathscr {R}}_0^S>1. It should be noted that the existence of an ergodic stationary distribution together with the unique exact probability density function can reveal all the dynamical properties of disease persistence in both epidemiological and statistical aspects. Next, some numerical simulations together with parameter analyses are shown to support our theoretical results. Last, through comparison with other articles, results are discussed and the main conclusions are highlighted.