Both Israel and Hamas committed war crimes in the early stages of the Gaza war, a United Nations inquiry has found.