Thousands of years ago, in the Middle East, many ancient peoples took refuge in caves to seek shelter from the elements (and to hide from other tribal groups). Having a cave was like having a pre-constructed house with climate control. In those caves, then as now, there were populations of roosting bats, and these bats were preyed upon by blood-sucking parasitic insects. These were the precursor to the modern bed bug: the Cimicid family, with each member of this parasitic classification feeding entirely on blood.
Cimex species specialize. They prefer to feed only from one type of animal, which allows them to develop specialized adaptations suited to finding and obtaining food (such as the mild anesthetic in their saliva). Over thousands of years, however, the ready availability of humans in those caves meant that hunting wasn’t a problem. The trait of being able to tolerate human blood became advantageous, and took only a small adaptation to accommodate.
When humans left those caves, began migrating, and opened up trade routes that expanded the boundaries of the known world, they brought the direct forerunners of Cimex Lectularius—the modern bed bug—with them. This ensured that these unwanted passengers would eventually focus on humans, losing their previous flexibility, and would develop traits particular to preying upon humans. One of the big ones, an adaptation to our sleep cycle, was noted by writers in both ancient Greece and Egypt, as far back as the 5th century BC.