When I say it is illegal to keep someone's passport, I quote Mr. Nasser Ahmed Al Osaiba, Emirati Partner and Lawyer at Global Advocates and Legal Consultants in UAE:
"Holding the employee's passport from him is illegal. If such action occurs, the staff can approach the nearest police station, and the company will have to hand over the passport there. Your company has no right to hold your passport. Retaining employees' passports by employers is against the UAE Labour Law."
The passport is clearly the property of the respective government that issues it to its nationals, and not even you have the right to hand it to someone who is unauthorized to handle it. In most cases, your employer also falls into the category of such unauthorized persons. So if somebody demands the passport from you, it is illegal in the UAE. Such a law may lead to the exploitation of employees.
Hope this answer resolves your query. Get back if you have any more doubts.
Regards.