Depends on you, the situation, the patient and the setting.
If you are a nursing student, NO. Do not even read further because it is NEVER OK.
There are some acutely psychotic patients that it goes without saying that you should never be alone with them. However, many psych patients are not the stereotypical psych patients that we see in movies and TV, and you would probably be fine if you were alone with them. Like colleennurse said, people can be very unpredictable (even if not a psych patient), so you should take precautions.
First, let another staff member know where you are going to be at all times. If you prefer, have them hover nearby.
Second, NEVER be behind a closed door or totally isolated with them unless you have a bona-fide reason to do so (e.g., giving them a shot). Leave the door open. If they want privacy, tell them that's why you're in the room. If the patient asks that the door be fully closed, tell them no. Or take them to a room where you know there is a video camera and/or windows, so at least someone can keep an eye on you.
Third, don't let the patient get between you and the door. Always have a clear escape route.
Fourth: be mindful of boundaries--yours and the patient's--at all times.
Fifth, if you're visiting a patient of the opposite sex, bring along a staff member of that same sex. That's for your protection, not so much for assault possibilities, but to protect against "he said, she said". Occasionally patients have made false accusations against staff, and no matter how out of it the patient is, any accusations made by them about you are taken seriously. Or again, bring them to the room with the video camera and/or windows.
Last: no matter the situation or the patient, if your Spidey sense starts tingling and you think it's a bad idea, DON'T DO IT.