Any that are worth playing are usually aware of this. The only courses I've seen where houses are so close to be in play were probably there before the homes were built and the initial course design isn't compatible with the developers planning. I've heard of buyers being required to sign a waiver, it's disclosed at the time the contract is signed not at closing. Most of the golf communities that were designed correctly have ample room for errant shots and homes are situated where they would be nearly impossible to hit unless it was intentional. I'm going out later and I'll try to take some pics. My home course has a few holes with homes on both sides but at the middle they are wide enough to land a commercial airliner. Only time you are within a few yards of homes is on tee boxes and where the cart path goes around the green. You'd have to hit a slice or hook completely off the course. The areas on either side of the fairway not intended for play are as wide as the fairway and rough. The only time I've been near anyone's yard is if the ball hits the cart path and takes a huge bounce.
Here's one that's near me:
That set of markers is 260 yards from the middle of the back tee box. Note that it's 24 yards from the edge of the fairway to the corner of that house. The FAIRWAY. Not the rough, the scrub, or any other such nonsense, but the FAIRWAY.
Interesting note about this course, BTW: It was a 27 hole, semi private Jack Nicklaus course and they blew up half of it for those houses. All of the stuff below and left of that hole used to be other holes.