Part of their mythology can be seen as sanctioning a ritual killing of the king, but not of a god. And also, it's a long way from ritual killing to actual killing. The truth is probably a lot less spectacular, which is that Cook was probably killed during a melee in which a bunch of Hawaiians were also killed. Before his death, Cook had attempted to take a Hawaiian king hostage in response to Hawaiians taking a bunch of stuff from Cook's boats. This was common practice for Cook. He had done the same thing in Tahiti and other Polynesian islands after islanders had taken European goods. Which, by the way, happened everywhere Cook went in the Pacific, so maybe he should have figured out that it was like a thing, that you were allowed to take stuff off boats in exchange for the right to hang out there.