Hi, I'd like to help you with your question.
It depends on whether or not you were committed against your will (called a 302). In this case, you can only be committed if someone feels you are a threat to yourself or someone else. If you are committed on a 302, it involves a legal procedure. To keep you in longer than 72 hours, a hearing with a judge needs to take place to see if you are still a danger to yourself or others.
If you took yourself to the hospital and went in voluntarily (called a 201), then you cannot be held against your will. You are free to refuse any treatment and you can leave at any time.
If you could not urinate for the sample, then I would think that the staff could give you more time to do so. If you are in the hospital, then there in little chance you could contaminate your urine in any way. Usually within an hour, most people can provide enough of a sample to be useful.
If you are combative in the hospital setting, the staff have the right to calm you through restraining you and placing you in an area where you are not able to harm others. They cannot lock you up or keep you there longer than necessary, but until you calm down they can restrict your movements. Most places try not to restrain people unless they really need to for the safety of others.
It sounds like you might have needed to contact a patient rights advocate. You have the right to have an advocate assist you in any mental health situation. If this occurs again, ask the staff for the available advocates and contact them. They will help you be sure you are being treated right.
I hope this has helped you,