Within synapsids, there was a change from a lizard-like sprawling posture (like in pelycosaurs) to a more erect stance. Non-eucynodont eutherapsids seem to have had a facultatively erect hindlimb and sprawling or semierect forelimbs. Eucynodonts seem to have had an obligatorily erect hindlimb and semierect forelimbs. Yet so many mammals (especially monotremes) and one tritylodontid seem to have had non-erect hindlimbs. What could have driven them to a non-erect hindlimb? Were there mammals with facultatively erect hindlimbs?
I think you are confused about what erect limbs means, monotremes have erect hindlimbs. Erect is not the same as pillar erect (which is exceedingly rare) Just because a limb is bent or a joint can rotate does not mean it is not an erect limb. More importantly terms like semi-erect don't actually mean much, it is a weak gradation not discrete categories. Like most things in biology nature does not respect our attempts to pigeon hole. Many animals can in fact switch between locomotive style.
To answer your second question, limb posture is often modified for specialized environments like aquatic living or burrowing. Which is why seal and mole limbs also have odd arrangements.