Units in the stack get the full HP increase, but ONLY if they are not damaged. If they are down even 1 point, the cap will rise upon advancement, but you will not get the health, without/until healing up to the cap. The computer then figures out how many guys with full health that is, and yes, reduces the number of guys in the squad.
As to being in town, it is part of the defense bonus, which also scales on level, so a high level stack gets a big boost to health cap, I have seen +100% a couple times, but similarly, I got the raised cap, but not the health to go with it.
One more thing to fix on the already significant pile....