They don't hold it for safety purposes. It's illegal if that is the honest intent. If the person to whom the passport is issued requests the passport and it is freely given then maybe. But again, what happens if the person(s) with access to the safe are not available?

I repeat a passport is the property of the government that issued it to you. No one (no employer or other government) has the right to retain it legally. You may freely give it to them for safekeeping but you have every right to ask for its return on demand. If the company refuses to do so, report them to the Labour Dept and the MoI.