Because 32-bit OS means the cpu has 32-bit architecture, which means it has 32 bit registers. How does this relate to RAM?
Registers point to a particular RAM address during cpu operation. Think of it as the RAM addresss needs to be loaded in register. If you can load only 32 bits in register you cannot put more than 2^32 bytes of data in it (4GB)
Further explanation:
So for example in 8-bit architecture if register's current value is 11111111 it is pointing to 1111111 address in RAM. Each address in RAM points to some value of size 1 byte. Address that is composed of 8 binary digits can have 2^8 (256) combinations for unique name. Each combination can store(point to) the value of 1 byte therefore hold up to 256 bytes.
So in this case if we had 512 bytes in RAM, we just cannot represent it all because 8 bit (8 binary digit) register can point only to 256 different combinations which is 256 bytes.
Same applies for larger numbers. 32 bit = 2^32 combinations to be used as a address = 429496... bytes or short 4 GB