That’s because the code responsible for setting the crouch height is, as far as I remember, constantly setting the capsule height, until the button is released AND the player is not in a space anymore where uncrouching is impossible. Hence why you cannot set the capsule height during crouch.
Also, a capsule component is nothing but a slightly more advanced sphere. It can never get smaller than its radius, since at its core it’s still that sphere. If you want an actual crouch height of 40, you need to set the radius to 40 as well. Though again, during crouch this is likely impossible. What you can do is set the sphere radius before you start your crouch, or just change the radius altogether.