The thing is, under the rules of war, protected installations (such as residential areas or even hospitals) lose their protection if they are being abused by a warring party for military operations. Otherwise, it would be an open invitation for anyone to do what Hamas did - force the other party between either risking getting shot at or violating rules of war.
No one forced Hamas to embed themselves among civilians. They did that on their own.