In-Universe, given the lack of basic toiletry facilities in his "plastic prison" (such as a sink with running water and a toilet) I think we can be reasonably certain that we're not seeing the whole thing. Either the staff periodically bring him a potty and a bowl of water or there's some kind of secondary room that isn't shown.
As to how he keeps clean-shaven, there are several options. When we see him in his prison, he's quite stubbly, suggesting that he hasn't shaved in quite a few days. This would tend to rule out his having daily access to a ceramic or obsidian razor. My personal guess would be that every week or so they give him a plastic tube of immac/veet or some other depilatory cream. Neither of these options would provide him with access to metal so either would be acceptable.
Out of universe, the decision to have him clean-shaven was taken after filming had started (you can see some early shots of him filmed with the beard in the video below). It seems likely that the Producers wanted to prevent any linkage between Gandalf and Magneto. Sir Ian speaks to this point in an online interview at mckellen.com
Interviewer : What do you think are the differences and similarities in Magneto and Gandalf?
McKellan : Gandalf has a beard/Magneto has a helmet.