Cutaway of an Imperial Roman domus (upper-class house in a city)
The well is built first, and possibly decades before the house, I would guess.
Sometimes they aren’t ‘true’ wells, but just cisterns used for water (via rain or plumbing) storage to keep it refreshingly cool.