At its heart, legalism is a desire to appear holy. It is trying to be justified before men and not God.
God does sometimes change our trying circumstances. But more often, He doesn't - because He wants to change us.