I think it is quite obvious: to destroy the Hamas infrastructure and to kill as many Hamas militants as possible, while minimising Israeli casualties.
If you have a better suggestion for how to destroy Hamas’ ability to continue to attack Israel I’m sure they would love to hear it.
It’s called symbiosis. They both profit from it.
How do I know? Because it evolved. Why did it evolve? Because it gives them an advantage.