Different soldiers, different groups participating with their own ideologies, different squads with different orders (capture hostages vs kill civilians). There's lots of different reasons and I don't think anyone could give you a good answer.
Frankly, I'm sure that at least some soldiers participating in this were given orders to kill civilians. A bunch of the men killed here would have served in the IDF and would be reservists. A bunch of the Palestians soldier are probably are all sorts of mentally fucked up from having grown up in Gaza, and need little if any encouragement to do this.
This is also just what war often actually is, which is why we are generally anti-war and why we say that Israel's past actions made this sort of violence inevitable. If you feel like this is bad--which frankly you should--you should be doing everything you can to promote peace. If Israel wanted to avoid this, it should have been doing everything it could have to work with the PA. Instead, it has continued to annex the West Bank, thereby making the Palestians who were willing to collaborate with them look like fools. When you make ever non-violent path towards freedom and justice impossible, this is what eventually happens.
You can't make people live in a pressure cooker their whole lives and then act surprised that they explode when the lid pops off.