1570s, "residence;" see resident + -cy. Hospital sense is from 1924.
residency res·i·den·cy (rěz'ĭ-dən-sē, -děn'-)n. The period during which a physician gets specialized clinical training.