Stall or stall warning? I would be 99% sure it was the latter.
Once you are in ALT, it follows a trajectory based on the rate-of-climb when it acquired. If you’ve flown through a positive shear/gradient and maintained airspeed, the instantaneous climb rate at capture might be above what the aircraft can sustain without trading speed for height. If the A/P is in, you have to disconnect or accept a loss of airspeed during the capture.