How can orbital resonance sometimes have a stabilising effect, whilst other times, it has a destabilising effect? I have just started learning about orbital resonance. I understand how bodies in orbital resonance will line up according to the orbital ratio number, and there will be increased gravitational effects upon alignment.
However, I do not understand how resonance can often have a stabilising effect, while other times, it is destabilising? For example, in the Io-Europa-Ganymede system, the 4:2:1 resonance has a stabilising effect. But also, I read that the gravitational perturbances when the moons align cause them to have elliptical orbits, so is it really a stabilising effect? There are other examples where orbital resonance completely prevents stability, like in the Kirkwood Gaps of the asteroid belt.
So my question is, how do orbital resonances form in the first place, and what determines if they are stable/unstable? Thank you.
According to my understanding, for an orbital resonance to be stable, there must be at least three circumstances present:

The forces on the bodies in resonance have to cancel out over time,
The momentary forces shouldn't be that high that the orbits are changed significantly,
after a perturbation, the bodies should pull each other back into resonance.

For example, the Trojans are in a 1:1 resonance around the Lagrange points of Jupiter, and the Galilean moons of Jupiter are in a 4:2:1 resonance. A 2:1 resonance wouldn't be stable at it's own because the gravitational forces would always apply at the same point, but the perturbances are cancelled out by the third moon, and the outer and inner moon are in a stable 4:1 resonance.
In general, a resonance can be stable, if the encounters of the objects are equally distributed, so imaginary lines between these points have point symmetry / a regular shape (for example a straight line across the orbits (3:1; 3:2), an equilateral triangle (4:1; 4:3), a square (5:1; 5:2), a pentagon or pentagram, etc.) But, the closer the orbits get to each other, the more unstable they get, because the deflection gets bigger, so those resonances only work if the bodies aren't too massive. 2:1 resonances can be relatively stable too, but without any other resonance preventing it, the eccentricity will rise over time and one of the bodies may be ejected. However, orbital resonances are only stable in certain circumstances, because if the eccentricity and/or the inclination are too high, the forces don't cancel each other out enough. But there still are some configurations in which highly inclined and eccentric orbits are stable.