Short answer: the license
Excluding hardware from the equation, it is mostly an artificial software restriction:
[The] limit is retrieved from the registry by calling a function named
ZwQueryLicenseValue, which is itself called from an internal procedure which Microsoft's published symbol files name as
Source: Licensed Memory in 32-Bit Windows Vista
Of course, license data stored in the registry even in an undocumented format might easily be changed by users, which they would have some incentive to try since Microsoft charges significantly different prices for different licenses. Microsoft therefore has an elaborate scheme for checking that the license data remains as Microsoft wants it. The kernel is the repository for whether the licensing data has been tampered with, and to this end exports two more functions,
Source: Software Licensing
This [undocumented] function asks the kernel whether the license data has been tampered with.
The internal use is in a timer that recurs approximately every hour. If the tamper state is found to be
4, then Windows stops. The bug check code is
0x1B as the first argument.
A practical example
Let's say you have a computer with 32 GiB of RAM, and you install Windows 7 Home Premium x64 (64-bit). In that case you would be limited to 16 GiB. If you were to use Windows Anytime Upgrade, and upgrade to a more expensive edition, suddenly the limit would be set to 192 GiB instead.
All Windows 7 editions share the same source code. The main difference is the number of features/limitations which are either enabled or disabled. Professional and higher client editions have no upper limit to how much RAM they can handle, and are just licensed to what Microsoft guarantees to support.
Additionally, the Windows 7 EULA explicitly says that you may not "use the software for commercial software hosting services", hinting Microsoft assumed that if you need more RAM that what the highest client edition is licensed to, then what you really want is a server license. Windows 7's server counterpart (that is, Windows Server 2008 R2) can use up to 2 TiB of RAM in the Enterprise and Datacenter editions.
As technology moves fast, what was acceptable yesterday might not be enough tomorrow. In order to catch up, Windows 8 raised the limits to 128 GiB and 512 GiB for the Core and Pro/Enterprise editions, respectively. That only applies to 64-bit versions, though: 32-bit versions are still capped at 4 GiB. The server version, Windows Server 2012, can address up to 4 TiB of RAM in the higher editions.