The rise of automated demand response and distributed energy resources is reshaping how energy flexibility is produced and coordinated. Algorithmic systems increasingly mediate between grid needs and household energy consumption, raising fundamental questions about consumer agency and system stability. Existing research treats demand response optimization, consumer behavior, and grid stability as largely separate domains. As a result, the field lacks a unified theory explaining how algorithmic coordination of flexibility interacts with human agency and affects system-level outcomes. This article develops a theory of algorithmic energy flexibility that integrates demand response, consumer agency, and grid stability into a coherent conceptual account. The theory explains flexibility as a socio-technical phenomenon rather than merely a technical resource. The theory is constructed through conceptual synthesis and theoretical integration of literature from energy demand studies, socio-technical systems theory, behavioral science, and grid operations research. No empirical data are collected or analyzed. The theory proposes that algorithmic energy flexibility is shaped by three core constructs: the mode of algorithmic coordination, the degree and type of consumer agency preserved, and the temporal and spatial requirements of grid stability. These constructs interact through mechanisms of automation-alienation, agency-preserving design, and stability feedback, moderated by institutional trust, fairness perceptions, and market design. The theory provides a new lens for understanding why some algorithmic demand response programs succeed or fail, and it offers testable propositions for future empirical research. It also informs the design of flexibility mechanisms that are both technically effective and socially legitimate.