Due to the end of the story arc with Hugh Jackman, the creators had no other choice.

Going to watch Logan, many fans of the X-Men franchise knew that this film would be the last for Hugh Jackman in the image of Wolverine. Nevertheless, not everyone was ready for the emotional roller coaster that the scriptwriter and director of Logan, James Mangold, had prepared for them. The end point of this breathtaking trip was the death of the protagonist, which was both a deception and an excess of audience expectations.

Commenting on Wolverine’s death, Mangold said in an interview with ComicBook:

Fewer people are involved in this process than you might think. At first it was just me and Hugh [Jackman]. Since this film was conceived as the last for him, it seemed logical that he would either go into the sunset or die. It was necessary to come up with a certain curtain for this story. This is a logical premise, isn’t it? Either we will have a final in the style of “Shane”, when the hero goes to unknown mountain ranges, or he needs to be killed. The first option was used in all previous films about Wolverine, but this time a different solution was obvious. There was a sense of the end that needed to be embodied on the screen, drawing a line under Hugh’s many years of legacy in this role.

Mangold also said that Fox had no hesitation in agreeing with the decision to kill Wolverine in the ending of Logan. According to the director, everyone perceived such an outcome as inevitable, but natural, because it was the end of a long legend.