Distance measurement through non-contact methods is perfectly feasible, and is used in many industrial applications. Not having this in a 3D printer is not a technology constraint but a cost and complexity one.
For instance, at the simplest level, proximity sensors such as Vishay TCRT5000 can be used, with fairly trivial microcontroller code required. The device consists of an infrared LED and a photodetector, which work by reflected infrared from a surface, such as the printer bed. Precision is not earth-shaking, but nor is the cost: $1.46 for 10 units.

For something slightly more sophisticated, fully integrated, serial interface proximity sensors using a similar reflective IR mechanism are available, e.g. Vishay VCNL3020 (~$3 each) and Austria Microsystems TSL2671 (~$1.60 each). Both of these have I2C interfaces, and eliminate the entire effort of modulating the IR LED and calibrating for ambient light.

Depending on the layer resolution of the 3D printer, this too may not provide sufficient precision and accuracy for the purpose. In such case, laser-based, diffraction-grating angular deviation sensors such as the Sick OD Mini product range are available. These are typically accurate down to tens of microns. Prices are pretty steep, making these unviable for domestic 3D printers. Such devices are commonly used in industrial grade machinery, including, presumably, additive manufacturing machinery.

Note that all the common distance sensing devices I have mentioned, used in the sensing range of interest, are based on infrared or occasionally visible light reflection, either using reflection intensity (low precision) or angular dispersion (high precision). Ultrasonic devices typically do not boast the degree of precision these optical devices can achieve.