Because the mountains aren't high enough to block all the rain clouds that come that way. This can be a function of:
A. Them actually being relatively low all around i.e. less than 1000m above sea level so they just don't block the rain, mountains of this size may seem small but if they're extensive and broken enough they'd still be impassable.
or
B. The mountains have wide passes at relatively low altitude that lets wet weather systems into the valley when they're moving toin the right direction, this could make for a distinct wet and dry season if there is something like a monsoon weather cycle operating.
Alternatively the water may be in the form of glacial melt in which case the precipitation that supplies init need not occur within the valley but rather on outward facing slopes with the glaciers twisting back into the valley. Or even in the form of springs feeding through porous rock into the valley from outside.
The fertility is a given, if there's enough water coming into the valley it will be depositing rich sediment into the valley bottom creating and renewing a rich soil layer.