c. 1300, "the crime or sin of stealing what is consecrated to God," from Old French sacrilege (12c.), from Latin sacrilegium "temple robbery, a stealing of sacred things," from sacrilegus "temple-robber, stealer of sacred things," noun use of adjective, from phrase sacrum legere "to steal sacred things," from sacrum "sacred object" (from neuter singular of sacer "sacred;" see sacred) + legere "take, pick up" (from PIE root *leg- (1) "to collect, gather").
The second element is not from religion, and the two words might not be related etymologically. From early 14c. as "improper or impious behavior." The transferred sense of "profanation of anything held sacred" is attested from late 14c.