Hamas had full internal control 2005-2023. I say "buy" but they're a government. Governments regularly use eminent domain to just take land. Governments don't have to pay. With all the buildings in Gaza, it seems ridiculous for you to suggest that Hamas couldn't find some to use exclusively for military purposes.