Because they are bargaining chips, that is why!
And, no, I am not going to excuse it. It is categorically wrong and morally as well as legally untenable!
But so is the "administrative detention" of Palestinians. "Administrative detention", for those not in the know, means "arresting and imprisoning people, never putting them in a court of law, but holding them on secret charges" - in other words: basically "hostage taking - but when you have a whole state and its associated machinery at your disposal, you can call it other things, or so ...". And, while I happen to be at it: yes, the supposedly "lawful" imprisonment of Palestinians supposedly "lawfully convicted" (but the court system is run by a state that oppresses them and crushes and resistance - violent and non-violent alike - with an iron fist) is also, to a very large extent, just "hostage taking, but we have a state aparatus to pretend this is okay"!
For the record: nothing, nothing, NOTHING can justify the attacks on Israeli civilians on 7 October.
But, also for the record: nothing, nothing, NOTHING can justify the systematic violence of the occupation either!
And if you keep on saying "but Hamas" ... pls note that you should be able to make the exact same argument, replacing "but the IDF and militant settlers" - and if you cannot, you have an issue!
For the record: I am not a Hamas supporter. Hamas sucks. As, for the record, does the so-called PA! If Fatah has any shred of decency left in it, it would just ... dissolve the PA and refuse to serve as the "coloniser sanctioned" police force, letting Israel bear the full brunt of what, as an occupying power, it really ought to - but it is somewhat telling that I think this is something I need to add this disclaimer in the first place!