When I refused to give it to them, on the basis of privacy, the employee said that Apple could not provide the service. He backed down a little when I asked to speak to his supervisor, but then said that not providing my passcode would void my iPhone's warranty. Eventually they performed the service without my passcode and had me perform the functional testing myself before walking out of the store.
I wonder how many thousands (millions?) of iPhone passcodes are stored in Apple's database? And of course the average owner probably doesn't think to change the passcode after the service is completed.
It is stored in a database, but the passcode is deleted immediately after the genius marks the service as completed.
I suppose if your device is beyond being able to operate then you are going to need to change your password or passcode when you get it back.
My MacBook Pro battery had to be replaced too and the Apple rep asked the same thing. I just told them I rather have them wipe the machine instead and they were happy to just put that in the service notes.