This describes an action that was completed before another past action (pluperfect). The past perfect (pluscuamperfecto) 'había apagado' indicates that when the speaker returned (past), the wife had already turned off the lights (action completed before that past moment).