A plain flap deflected 40 degrees is largely stalled (...)
Flaps stall at 40° according to an answer on Quora, why is this so when typical airfoils stall at 15°?
Flaps don't stall, it is the whole wing they are attached to. Stall normally means flow separation, but there are flaps which are designed with flow separation in their regular operating range (split flaps, for example).
Flaps change the camber of a wing such that more or less lift is created at the same angle of attack. More lift means more suction on the upper side, so the pressure recovery over the rear part of the wing needs to be steeper. Also, the surface kink of a deflected flap causes another suction spike, followed by an equally steep pressure rise. Now you have to know that any pressure rise puts big strain on the slowed-down air in the boundary layer. Too much, and the flow will separate. Enough separation and the wing stalls.
It is easy to see that more flap deflection means higher stress on the boundary layer at the same angle of attack. Therefore, the wing's stall angle of attack decreases with increasing flap deflection (the wing reference line from which the angle of attack is measured doesn't change with flap deflection, by the way). The Quora answer you linked to is full of misconceptions - please forget that nonsense about jets of air shooting from the slots. Better read this paper by a renowned expert (A. M. O. Smith, McDonnell-Douglas) - he gets the physics of flaps right!
Flaps are located in the downwash of a wing. Their local angle of attack is not equal to their deflection angle, but equal to the deflection angle minus the angle the downwash leaves the trailing edge of the wing.