Thor blames Loki for Odin's death, implying that he would not have died had he not been exiled from Asgard. Of course, Thor might be mistaken about this.
Conversely, Loki did not seem to have expected Odin to die, though, well, this is Loki so he might be lying about that.
Taking these two points together, and assuming for the sake of argument that they are more or less correct, I believe that being exiled (combined with extreme old age) left Odin without sufficient strength to keep Hela imprisoned, and the effort simply left him too exhausted to survive, particularly given that he had no particular wish to live any longer after the death of his wife.
That suggests that he could have chosen to release Hela earlier rather than giving up his own life keeping her imprisoned for as long as possible, but she would have immediately killed or imprisoned him anyway, and gone on to attack Asgard without warning. By holding on as long as he did, and by dying in the way he chose, he was able to ensure that Thor and Loki were at least aware of the attack, that
he could continue to give Yoda-style advice at critical moments,
the crown of Surtur was available for the final denouement.
This is speculative, of course, so perhaps someone else can provide a better answer based on Word of God or other canon evidence. But it does seem to fit the mood of both the scene in question and the movie as a whole.