Recovering from stall itself states that the aircraft is below stall speed. So how does recovering from that stall lead to exceeding critical mach.
The second type is a high speed stall and is caused by shock-induced flow separation when the aircraft approaches Mach 1. In this case, the aircraft will accelerate to a higher flight Mach number where its maximum lift coefficient is smaller and causes lift to drop below weight. Here stall is caused by a speed increase, hence the name.
Lift coefficient variation over Mach number (picture source)
In the coffin corner, the highest point in the envelope of subsonic high performance aircraft, both speeds coincide. Now the aircraft can fly only at one speed, both a speed decrease and a speed increase will cause stall. When the plane recovers from a low speed stall while flying near the coffin corner, it needs to speed up and consequently runs the risk of accelerating beyond the critical Mach speed at which the lift coefficient drops and causes a high speed stall. Recovery is only possible by sinking into higher density and warmer air where the difference between both stall speeds widens and more lift can be created.
Generally, this happens to jets with straight or moderately swept wings which are powerful enough to fly high and fast but are not designed to exceed Mach 1. The Lockheed U-2 would be a prime example.
Stall can happen in cruise, at the absolute ceiling. The aircraft stalls at 40,000 ft or higher and at a speed close to cruise, like what happened with AF 447. In that case the aircraft was in a fully developed stall and falling to the ground in a more or less level attitude, at terminal velocity.
Recovery would have been initiated with nose down command, and then the aircraft starts to dive nose down, picking up speed. Only when the Angle of Attack is within normal operating range should the pilot start pulling the nose up - slowly, in order not to exceed the structural limit of 2.5g.
What happens in a stall in the Coffin Corner is described in this answer.
The higher an aircraft flies, the stall speed and critical mach get closer until at the absolute ceiling they are the same value.
Lets say you are in an airliner that is 5,000 feet below absolute ceiling and the two speeds are 40 knots apart and you are flying right in the middle of the two speeds. The pilot pulls the stick all the way back so that a full stall develops. At stall the nose drops. The weight of the aircraft is now accelerating downwards, possibly out of control, with engines still on cruise power and the critical mach is so close.
While this simple example would be very hard to imagine, due to stick shakers, fly by wire etc, there have been accidents in the past due to these reasons, where confusion or other factors have led to the initial loss of control.
I would have thought that a better pilot is needed on the recovery (to recover while preventing over speed) than the one that got you into the situation to begin with, so pilots are trained (and electronic aircraft designed) to avoid the situation in the first place!