Everyone (in the U.K. anyway) has a right to an appropriate treatment. That treatment sometimes has to accommodate various religious beliefs. If, and it sounds as though they could have done in this case, the beliefs can be accommodated then they should take measures to treat that person safely within their wishes.
The judge thought so anyway after looking at the evidence.