Usually, there is one degree of separation: "X lives in the same building with a terrorist". But I think a stronger point is that there is really no way for X to know that or do much about it, given limited living space in Gaza. But on the other hand, when Hamas starts a shooting war with Israel, it is likewise difficult for Israel to be able to hit its enemies that are hiding among civilians. That argument cuts both ways.Besides yet unsubstantiated claim about reality, it is a rather nasty assumption of guilt by possibly tenuous association. How would you feel if your house was destroyed because there was a terrorist connection within six degrees of separation?
Best solution would be for Hamas to realize that open warfare isn't the way, and focus on rebuilding and diplomacy.
Except the terrorists don't live there--they hide out there in times of war. Otherwise I agree with your one degree of separation point.
Standard military practice is that anything used for military purpose is a valid target no matter what other use it might have. Thus a building being used as a hideout by a commander is a valid target--the fact that it's also a civilian house doesn't change this, it just makes the situation a war crime by the person doing the hiding out.