Ask at an appropriate time and always be polite. Also, make sure your request is reasonable — if you want a midnight checkout, just pay for an extra night. If there's no one coming into your room on the day you are vacating it, the hotel will probably let you sleep in on your last day.